HTML Styles
You can already build page structure and point to other files with paths. The next question beginners ask is how to change how content looks: text color, background, and size. In early HTML practice you can do that with the style attribute. It is a small doorway into CSS ideas — useful for demos — while full site design will move into proper CSS later in your learning path.
What is the style attribute?
The style attribute lets you attach CSS declarations directly to one HTML element’s start tag. The browser reads those declarations and paints that element accordingly. You are not inventing a second language from scratch: you are writing short CSS rules in a place HTML already provides. That makes inline style a good teaching tool, even though professional projects rarely keep all design inside attributes.
Direct answer
Add appearance with style="property: value;" on an element. Starter properties include color (text foreground), background-color (the area behind the content), and font-size (text size). Put the whole list inside quotes. Separate multiple declarations with semicolons. For real multi-page sites, prefer a CSS file or a <style> block so you do not repeat the same look on every tag — but for this lesson, focus on reading and writing clear inline declarations.
Property and value, one at a time
Each declaration has a property (what you want to change) and a value (how it should look). A colon sits between them. Beginners should learn a few properties well before memorizing a huge list.
One property per paragraph
html<p style="color: blue;">Blue text</p>
<p style="background-color: lightyellow;">Yellow background</p>
<p style="font-size: 24px;">Larger text</p>
Reading the example
color: bluechanges only the text color of that paragraphbackground-color: lightyellowcolors the background behind the textfont-size: 24pxsets text size;pxis a common beginner unit- Each paragraph has its own
style="..."so the three effects stay separate and easy to see - Named colors like
bluework for practice; later you will also see hex values such as#336699
If nothing changes in the browser, confirm you saved the file, refreshed the page, and kept the quotes around the entire style value.
Several declarations in one attribute
You can combine declarations inside a single style attribute. Keep the list short so the HTML stays readable. End each declaration with a semicolon — including a final one is fine and often clearer when you edit later.
Combined style declarations
html<p style="color: navy; background-color: #f0f0f0; font-size: 18px;">
Navy text on a light gray background
</p>
Why this pattern matters
- One element can carry color, background, and size together
- Semicolons separate the declarations so the browser can parse each pair
#f0f0f0is a hex color; it is optional for beginners but common in real CSS- The visible sentence inside the paragraph is normal HTML text; only the
styleattribute changes appearance
Avoid packing ten design decisions into one attribute on day one. Learn the syntax with two or three clear properties first.
Style on different elements
The style attribute is not limited to p. Headings, spans, and many other elements can use it the same way. That helps you see that style follows the element you attach it to — not a magical global switch.
Heading and paragraphs with style
html<h1 style="color: darkgreen;">Garden Notes</h1>
<p style="color: #333333;">Ordinary body text in a dark gray.</p>
<p style="background-color: honeydew; font-size: 20px;">Highlighted tip with a soft green background.</p>
What to notice
- The
h1color does not automatically restyle the paragraphs - The second paragraph combines background and font size
- Inline style is local: it affects that element (and, by normal CSS rules, can influence children — but keep demos simple for now)
Inline style now, CSS later
Inline style is fast for experiments. It becomes painful when twenty pages need the same navy heading color and you must edit twenty attributes. Shared CSS — a <style> block in the document head, or an external .css file — keeps look-and-feel in one place. This course includes dedicated CSS learning ahead. For this HTML session, your job is to understand the property:value idea and to write a few correct inline examples without treating inline style as the final architecture for a whole website.
Practice in your editor
- Create a page with one
h1and three short paragraphs. - Give the first paragraph a text
color. - Give the second a
background-color. - Give the third a combination of
colorandfont-size. - Optionally color the
h1with its ownstyle. - Save and refresh. Confirm each block looks different.
- Break one example on purpose (remove a quote or a
px), refresh, see the failure, then fix it.
Working through a failed style teaches quotes and units faster than only copying perfect samples.
Mistakes that hide your styles
- Forgetting quotes around the value:
style=color:redis invalid in normal HTML attribute writing - Mixing up
color(text) withbackground-color(behind the text) and thinking “color did nothing” - Omitting units where size needs them (
font-size: 24instead of24pxin many beginner cases) - Using a word processor that replaces straight quotes with curly quotes inside attributes
- Stuffing a whole page design into inline styles instead of learning shared CSS next
- Changing the file but forgetting to save before refresh — the browser still shows the old version
Summary
- The
styleattribute adds CSS declarations to one HTML element - Write
property: value;and keep the whole list inside quotes - Starter properties:
color,background-color,font-size - Combine a few declarations with semicolons; keep demos short and readable
- Inline style is excellent for learning and tiny experiments, not for maintaining an entire site’s design
- Shared CSS comes next on the learning path when you want one place to control look-and-feel
- Always verify with save + refresh, and check quotes and units when styles “mysteriously” fail
🧠 Test Your Knowledge
Test Your Knowledge
Challenge yourself with this interactive quiz and see how well you understand the topic
📝 Instructions
- Read each question carefully
- Select the best answer for each question
- You can retake the quiz as many times as you want
- Your progress will be shown at the top