3 min read · Free · No login needed
The style attribute lets you add CSS directly to an HTML element. It is called inline styling. It is the quickest way to change how one element looks, and it is perfect for learning, because you see the result immediately.
style="color: red;"style="background-color: yellow;"style="font-size: 20px;"style="font-family: Arial;"style="text-align: center;"Each style is written as property: value; and multiple styles are separated by semicolons: style="color: white; background-color: navy; font-size: 18px;".
Inline styles are good for quick experiments and for one-off changes. But if ten elements on your page need the same look, writing the same style ten times is wasteful. That is what a <style> block or a separate CSS file is for — you will learn both in the HTML CSS lesson.
red), as hex codes (#e13611), or as rgb values (rgb(225, 54, 17)). Hex codes give you exact control.The style attribute lets you add CSS rules to one single element. CSS is the language that controls looks — colours, fonts, sizes, spacing. The style attribute is the quickest way to try CSS: you write the rules right inside the tag, and the browser applies them to that element only.
| Property | Value | Description |
|---|---|---|
color | a colour | The colour of the text. |
background-color | a colour | The colour behind the text. |
font-size | like 20px | How big the text is. |
font-family | like Arial | Which font the text uses. |
text-align | left, center, right | Where the text sits in its line. |
Each rule is written as property: value;, and rules are separated by semicolons. Here the same paragraph is styled two ways:
<p style="color: red;">Red text.</p> <p style="color: blue; font-size: 20px;">Big blue text.</p>
style attribute works on every HTML element — it is called a global attribute. But it only styles that one element. If ten paragraphs need the same colour, you would have to write the same style ten times.colour instead of color — CSS uses American spelling.<!DOCTYPE html>, <html>, <head> and <title>Styles</title> — the usual page skeleton. The title shows on the browser tab.<p style="color: red;"> — the style attribute adds CSS to this one paragraph only. The color property changes the text colour to red.<p style="background-color: yellow;"> — the background-color property colours the area behind the text, not the text itself.<p style="font-size: 24px;"> — the font-size property makes the text bigger. The value is measured in pixels.<p style="text-align: center;"> — the text-align property moves the text to the centre of the line. Each paragraph is styled on its own, so the others are not affected.<!DOCTYPE html>
<html>
<head>
<title>Styles</title>
</head>
<body>
<p style="color: red;">This text is red.</p>
<p style="background-color: yellow;">Yellow background.</p>
<p style="font-size: 24px;">Big text.</p>
<p style="text-align: center;">Centred text.</p>
</body>
</html>
Change the code below and press Run to see the result instantly. No file to save, no login needed.
The questions learners ask most about this lesson — read the question, then open it to see the answer.
It lets you add CSS directly to one HTML element. It is called inline styling and is the quickest way to change how one element looks.
Write each style as property colon value semicolon, and separate multiple styles with semicolons.
When the same look repeats on many elements. Writing the same style ten times is wasteful; a style block or CSS file is better.
AI can write code for you, but it cannot think for you. When you learn HTML yourself, your brain builds the real skill: you understand why a page looks the way it does, you can fix it when it breaks, and you can answer it in an exam or an interview without help. That is the skill that gets you a job — not a copied answer.
Finish all 35 lessons, pass the test (80%), pay ₹10 and get your certificate.
Take the testPrefer watching? Video courses teach the same topics step by step.
Free tutorials teach you the basics. Our paid courses add live projects, mentorship and a certificate.
Browse all coursesAsk about courses, website & more
Request human callback:
Please log in to download. You will stay on this page after logging in!
New here? Register now →