-
Hajipur, Bihar, 844101
Hajipur, Bihar, 844101
HTML5 Basics
HTML Introduction
HTML Editors
HTML Basic
HTML Elements
HTML Attributes
HTML Headings
HTML Paragraphs
HTML Styles
HTML Formatting
HTML Quotations
HTML Comments
HTML Styling and Design
HTML Links and Media
HTML Layout and Structure
HTML Tables
HTML Lists
HTML Block & Inline
HTML Div
HTML Classes
HTML Id
HTML Head
HTML Layout
HTML Responsive
HTML Computercode
HTML Semantics
HTML Forms
HTML Forms
HTML Form Attributes
HTML Form Elements
HTML Input Types
HTML Input Attributes
Input Form Attributes
HTML Graphics
HTML APIs
HTML Advanced Topics
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.
HTML5 Basics
HTML Introduction
HTML Editors
HTML Basic
HTML Elements
HTML Attributes
HTML Headings
HTML Paragraphs
HTML Styles
HTML Formatting
HTML Quotations
HTML Comments
HTML Styling and Design
HTML Links and Media
HTML Layout and Structure
HTML Tables
HTML Lists
HTML Block & Inline
HTML Div
HTML Classes
HTML Id
HTML Head
HTML Layout
HTML Responsive
HTML Computercode
HTML Semantics
HTML Forms
HTML Forms
HTML Form Attributes
HTML Form Elements
HTML Input Types
HTML Input Attributes
Input Form Attributes
HTML Graphics
HTML APIs
HTML Advanced Topics