SA-21/06, C-11, Asapur, Varanasi, UP support@kamaldnp.com +91 8318013442
HTML
1. HTML Introduction: What is HTML? Learn with Examples 2. Best Free HTML Editors: Notepad to VS Code for Beginners 3. HTML Basic Structure: Doctype, Head, Body Explained 4. HTML Elements Explained: Tags, Content & Empty Elements 5. HTML Attributes List: href, src, alt, width, title & More 6. HTML Headings h1 to h6: Which Heading Tag to Use When 7. HTML Paragraphs: p Tag, br Line Breaks & pre Text 8. HTML Style Attribute: Colour, Font Size & Alignment 9. HTML Text Formatting Tags: bold, italic, mark & More 10. HTML Comments: How to Add Notes & Hide Code in HTML 11. HTML Colors: Names, HEX, RGB & HSL Colour Codes 12. HTML CSS: Inline, Internal & External Stylesheets 13. HTML Links: a Tag, href, New Tab & Email Links 14. HTML Images: img Tag, src, alt, Width & Formats 15. HTML Favicon: Create & Add a Browser Tab Icon 16. HTML Title Tag: How to Write a Good Page Title 17. HTML Tables: table, tr, th, td, colspan & rowspan 18. HTML Lists: ul, ol, dl & Nested Lists Explained 19. HTML Block vs Inline Elements: div, p, span Explained 20. HTML Div Tag: Group Content & Build Page Layouts 21. HTML Class Attribute: Style Many Elements at Once 22. HTML id Attribute: Unique IDs, Links, CSS & JavaScript 23. HTML Iframes: Embed YouTube, Maps & Pages in HTML 24. HTML JavaScript: script Tag, Clicks & First Example 25. HTML File Paths: Relative vs Absolute Paths Explained 26. HTML Head Element: title, meta, charset & viewport 27. HTML Layout: header, nav, main, footer Page Structure 28. HTML Responsive Design: Viewport, Images & Media Queries 29. Semantic HTML Tags: header, nav, main, article & footer 30. HTML Forms: input, label, select, checkbox & Submit 31. HTML Entities: & < > © with Examples 32. HTML Audio & Video Tags: controls, source & Fallback 33. HTML Accessibility: alt Text, Labels, Landmarks & ARIA 34. HTML Meta Tags & SEO: charset, viewport, OG Tags 35. HTML Quotations: blockquote, q, cite, abbr & address
Final Test — Certificate ₹10
Try this code live
Lesson 8 of 35

HTML Style Attribute: Colour, Font Size & Alignment

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.

Diagram — see how it fits together
Infographic: the style attribute

What you can change

  • Text colour: style="color: red;"
  • Background colour: style="background-color: yellow;"
  • Font size: style="font-size: 20px;"
  • Font family: style="font-family: Arial;"
  • Alignment: 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;".

When to use it — and when not to

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.

Tip: Colours can be written as names (red), as hex codes (#e13611), or as rgb values (rgb(225, 54, 17)). Hex codes give you exact control.

What the style attribute is

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.

Common CSS properties

PropertyValueDescription
colora colourThe colour of the text.
background-colora colourThe colour behind the text.
font-sizelike 20pxHow big the text is.
font-familylike ArialWhich font the text uses.
text-alignleft, center, rightWhere 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>
Note: The 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.
Tip: Use the style attribute for quick experiments. The moment a style repeats on more than one element, move it into a CSS class instead — one place to change it later.

Common mistakes

  • Forgetting the semicolon between two rules — the second rule is then ignored.
  • Writing colour instead of color — CSS uses American spelling.
  • Styling every element separately instead of using a class for repeated styles.
  • Using the style attribute for the whole page layout — that job belongs in a stylesheet.

Example explained

  • <!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.

Example

Example
<!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>

Output

Output — how it looks in the browser
Output of HTML Style Attribute: Colour, Font Size & Alignment

Try it yourself — live editor

Change the code below and press Run to see the result instantly. No file to save, no login needed.

Result

Frequently asked questions

The questions learners ask most about this lesson — read the question, then open it to see the answer.

1. What is the style attribute?

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.

2. How do I write more than one style on an element?

Write each style as property colon value semicolon, and separate multiple styles with semicolons.

3. When should I not use inline styles?

When the same look repeats on many elements. Writing the same style ten times is wasteful; a style block or CSS file is better.

Why learn this yourself — and not just ask AI?

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.

Get certified — just ₹10

Finish all 35 lessons, pass the test (80%), pay ₹10 and get your certificate.

Take the test

Prefer watching? Video courses teach the same topics step by step.

Go further with a full course

Free tutorials teach you the basics. Our paid courses add live projects, mentorship and a certificate.

Website Design Using WordPress 3 Days (Basic to Advanced)
₹199
View
Full Stack PHP Development Course 2026
₹3,000
View
Website Design & Development Workshop 2026
₹299
View
Browse all courses
HTML — Lessons
1. HTML Introduction: What is HTML? Learn with Examples 2. Best Free HTML Editors: Notepad to VS Code for Beginners 3. HTML Basic Structure: Doctype, Head, Body Explained 4. HTML Elements Explained: Tags, Content & Empty Elements 5. HTML Attributes List: href, src, alt, width, title & More 6. HTML Headings h1 to h6: Which Heading Tag to Use When 7. HTML Paragraphs: p Tag, br Line Breaks & pre Text 8. HTML Style Attribute: Colour, Font Size & Alignment 9. HTML Text Formatting Tags: bold, italic, mark & More 10. HTML Comments: How to Add Notes & Hide Code in HTML 11. HTML Colors: Names, HEX, RGB & HSL Colour Codes 12. HTML CSS: Inline, Internal & External Stylesheets 13. HTML Links: a Tag, href, New Tab & Email Links 14. HTML Images: img Tag, src, alt, Width & Formats 15. HTML Favicon: Create & Add a Browser Tab Icon 16. HTML Title Tag: How to Write a Good Page Title 17. HTML Tables: table, tr, th, td, colspan & rowspan 18. HTML Lists: ul, ol, dl & Nested Lists Explained 19. HTML Block vs Inline Elements: div, p, span Explained 20. HTML Div Tag: Group Content & Build Page Layouts 21. HTML Class Attribute: Style Many Elements at Once 22. HTML id Attribute: Unique IDs, Links, CSS & JavaScript 23. HTML Iframes: Embed YouTube, Maps & Pages in HTML 24. HTML JavaScript: script Tag, Clicks & First Example 25. HTML File Paths: Relative vs Absolute Paths Explained 26. HTML Head Element: title, meta, charset & viewport 27. HTML Layout: header, nav, main, footer Page Structure 28. HTML Responsive Design: Viewport, Images & Media Queries 29. Semantic HTML Tags: header, nav, main, article & footer 30. HTML Forms: input, label, select, checkbox & Submit 31. HTML Entities: & < > © with Examples 32. HTML Audio & Video Tags: controls, source & Fallback 33. HTML Accessibility: alt Text, Labels, Landmarks & ARIA 34. HTML Meta Tags & SEO: charset, viewport, OG Tags 35. HTML Quotations: blockquote, q, cite, abbr & address
Final Test — Certificate ₹10

🤖 KAMALDNP AI Assistant

Ask about courses, website & more

Hi! I'm KAMALDNP AI Assistant. Ask me about our courses, website features, or anything else! 😊
Please wait 5s...
🤖 KAMALDNP Assistant ✕

Request human callback:

🔐 Login Required
✕

Please log in to download. You will stay on this page after logging in!

New here? Register now →