The style attribute in HTML
- 24-07-2022
- Trung Minh
- 0 Comments
In this article we will learn the style attribute in HTML , this is the attribute used to adjust the display for the HTML tags themselves.
Since we haven't learned CSS yet, I won't talk too much about technical knowledge like selectors, ways to add CSS.. Instead, I will guide each effect and introduce the CSS properties that make that effect. .
Mục lục
What is the style attribute in HTML?
All HTML tags have this style attribute. It is used to add CSS, change the default display of that HTML tag. The syntax is as follows:
<tagname style="CSS_PROPERTY">
Where CSS_PROPERTY is the code used to set the interface for the tag itself. For example, set the background, change the font color, change the font size, set the display position on the interface …
The value of CSS_PROPERTY is of the form key:value
, if there are many CSSs, use the ;
to separate them.
Example : Set the background to red for the div tag.
<div style="background:red">Học HTML Style tại web888.vn</div>
How to use the style attribute in HTML
Style background
When you set the background to the style attribute, you can change the background color for that HTML tag.
<div style="background:red">Học HTML Style tại web888.vn</div>
Style font color
You can also change the font color using the color property.
<div style="color:red">Học HTML Style tại web888.vn</div>
Style font size
The font-size property changes the size of the font. Please put it in the style to apply it.
<div style="font-size: 50px">Học HTML Style tại web888.vn</div>
Add more CSS to the style . attribute
To add more effects to the style, separate them with semicolons. See the example below for better understanding.
<div style="font-size: 50px;color:red">Học HTML Style tại web888.vn</div>
So you already know how to use the style attribute in HTML. Good luck!