-
Hajipur, Bihar, 844101
HTML styles are used to add formatting and visual appearance (like color, font, size, background) to HTML elements. The most common way to apply styles is using the style
attribute directly inside an HTML tag.
<tagname style="property: value;">Content</tagname>
<p style="color: red;">This is red text.</p>
Property | Description | Example Value |
---|---|---|
color |
Text color | red, blue, #ff0000 |
font-size |
Size of the text | 14px, 1.2em |
background-color |
Background color | yellow, #f0f0f0 |
text-align |
Text alignment | left, center, right |
font-family |
Font type | Arial, "Times New Roman" |
border |
Adds a border | 1px solid black |
<p style="color: green;">This text is green.</p>
<p style="font-size: 20px;">This is larger text.</p>
<p style="background-color: lightblue;">This has a background color.</p>
<p style="text-align: center;">This text is centered.</p>
You can apply multiple styles by separating them with semicolons:
<p style="color: blue; font-size: 18px; text-align: right;">
Styled paragraph.
</p>
Inline style: style="..."
inside an HTML tag
CSS (better for large projects) is written in <style>
or external .css
files
Inline style is quick, but not preferred for big projects.
Q1. Write a paragraph with text color set to red using the style
attribute.
Q2. Display a heading with font size 30px.
Q3. Add a background color of yellow to a <div>
.
Q4. Center-align a paragraph using inline styles.
Q5. Use font-family
to change paragraph text to Arial.
Q6. Add a border to a heading using inline style.
Q7. Write a paragraph with multiple styles: color blue, font-size 18px, and text-align right.
Q8. Create three differently styled paragraphs using style
attribute.
Q9. Add background color and text color to a single line of text.
Q10. Make a <p>
tag appear with green color, 20px size, and bold text.
Q1: Which attribute is used to add inline styles in HTML?
Q2: What will this code '<p style="color: red;">Text</p>' do?
Q3: How do you set the background color using inline style?
Q4: Which is correct to center-align a paragraph text?
Q5: What is the correct format for multiple styles?
Q6: Which property sets the text font in HTML inline style?
Q7: What unit is used for font-size in inline style?
Q8: Which color value is valid in HTML style?
Q9: Inline styling is best used for:
Q10: What happens if you write style without quotes?