style attribute
Places CSS declarations directly on one element.
Learn Inline CSS as the bridge between clean HTML and professional CSS: visual hierarchy, maintainable styling, responsive behavior and live practice.
HTML styling foundation
Inline CSS uses the style attribute directly on an HTML element. It can be useful for tiny experiments, email templates, generated one-off values or dynamic CSS custom properties.
The danger is maintenance. When every element has its own style attribute, the design system disappears. You cannot easily reuse, search, override or improve the styling later.
Learn inline CSS so you understand it, but do not build your normal website styling around it.
Places CSS declarations directly on one element.
Inline styles override many normal stylesheet rules.
Useful for generated values such as progress, coordinates or email fallbacks.
Repeated inline styling becomes hard to update fast.
Syntax and structure
Inline CSS does not use selectors because it already sits on the element being styled.
<article class="progress-card" style="--progress: 72%;"> <h1>HTML progress</h1> <div class="progress-bar" aria-label="72 percent complete"> <span></span> </div> </article> <style> .progress-bar span { width: var(--progress); } </style>
<h1 style="font-size: 42px; color: red; margin: 0;">Title</h1> <p style="font-size: 18px; color: #555; margin-top: 14px;">Text</p> <a style="color: red; font-weight: bold; text-decoration: none;">Link</a> <button style="background: red; color: white; border-radius: 99px;">Send</button>
HTML quick reference
Use these patterns when you need the syntax quickly. Each example has its own anchor, so search engines and readers can land directly on the exact pattern instead of only at the top of the lesson.
A clean version of the markup from this lesson. Use it when you need the correct HTML shape quickly.
<article class="progress-card" style="--progress: 72%;"> <h1>HTML progress</h1> <div class="progress-bar" aria-label="72 percent complete"> <span></span> </div> </article> <style> .progress-bar span { width: var(--progress); } </style>
Meaningful markup that stays understandable before CSS and JavaScript are added.
The starting point from the practice lab. Change the HTML first, then use CSS only for presentation.
<article class="score-card" style="--score: 68%;"> <p class="eyebrow">Course progress</p> <h1>HTML Styling</h1> <div class="meter" aria-label="68 percent complete"><span></span></div> <p>Only the progress value is inline. The design stays in CSS.</p> </article> <style> body { margin: 0; min-height: 100vh; display: grid; place-items: center; font-family: Inter, system-ui, sans-serif; background: #07111f; color: white; } .score-card { width: min(680px, calc(100% - 32px)); padding: 32px; border-radius: 24px; background: #101a2d; } .eyebrow { color: #8cffc1; font-weight: 800; text-transform: uppercase; } .meter { height: 16px; overflow: hidden; border-radius: 999px; background: #263247; } .meter span { display: block; height: 100%; width: var(--score); background: linear-gradient(90deg, #8cffc1, #62d5ff); } p { color: #cfd8e6; line-height: 1.7; } </style>
A complete practice snippet that shows how the HTML behaves in context.
A weak pattern from the lesson. Use it as a warning sign when reviewing real pages.
<h1 style="font-size: 42px; color: red; margin: 0;">Title</h1> <p style="font-size: 18px; color: #555; margin-top: 14px;">Text</p> <a style="color: red; font-weight: bold; text-decoration: none;">Link</a> <button style="background: red; color: white; border-radius: 99px;">Send</button>
A recognizable mistake you can search for and refactor.
Rules that matter
Styling is not only making something look nice once. Good CSS stays readable, reusable and predictable while the project grows.
Inline CSS is strongest when it expresses one unique value, not a reusable component style.
If multiple elements need the same look, use a class and write CSS once.
Inline styles can make normal CSS harder to override.
The style attribute should not replace semantic HTML or accessible text.
CSS variables in style attributes can connect backend or JavaScript values to CSS safely.
Long style attributes are hard to read and usually signal that CSS belongs in a stylesheet.
Production thinking
This matters because beginners often discover style="" first and then use it everywhere. That works for one element, but it collapses when the project grows.
Inline styles can create contrast and focus problems just like any CSS. Do not remove focus outlines or rely only on color because it is quick.
Use inline CSS intentionally: email HTML, critical one-off values, generated CSS variables or prototyping. Move reusable styling to internal or external CSS.
Inline CSS does not directly improve SEO. It can hurt maintenance if the page becomes messy, slow or inconsistent.
Live code lab
Edit the HTML or CSS, then use Run to refresh the preview. The preview is isolated, so links and forms stay inside this practice area.
Mini assignment
Practice assignment
Try it yourself
Self-check
Do not only read this page. Answer these questions out loud or write the answers in your own notes. If one answer feels vague, revisit the examples before moving on.