CSS (Cascading Style Sheets) is used to style HTML elements.
Using styles in HTML
How to add style information inside the <head> section.
Link that is not underlined
How to make a link that is not underlined, with the style attribute.
Link to an external style sheet
How to use the <link> tag to link to an external style sheet.
CSS was introduced together with HTML 4, to provide a better way to style HTML elements.
CSS can be added to HTML in the following ways:
The preferred way to add CSS to HTML, is to put CSS syntax in separate CSS files.
However, in this HTML tutorial we will introduce you to CSS using the style attribute. This is done to simplify the examples. It also makes it easier for you to edit the code and try it yourself.
You can learn everything about CSS in our CSS Tutorial.
An inline style can be used if a unique style is to be applied to one single occurrence of an element.
To use inline styles, use the style attribute in the relevant tag. The style attribute can contain any CSS property. The example below shows how to change the text color and the left margin of a paragraph:
To learn more about style sheets, visit our CSS tutorial.
The background-color property defines the background color for an element:
The background-color property makes the "old" bgcolor attribute obsolete.
The font-family, color, and font-size properties defines the font, color, and size of the text in an element:
The font-family, color, and font-size properties make the old <font> tag obsolete.
The text-align property specifies the horizontal alignment of text in an element:
The text-align property makes the old <center> tag obsolete.
An internal style sheet can be used if one single document has a unique style. Internal styles are defined in the <head> section of an HTML page, by using the <style> tag, like this:
An external style sheet is ideal when the style is applied to many pages. With an external style sheet, you can change the look of an entire Web site by changing one file. Each page must link to the style sheet using the <link> tag. The <link> tag goes inside the <head> section:
|<style>||Defines style information for a document|
|<link>||Defines the relationship between a document and an external resource|
In HTML 4, several tags and attributes were used to style documents. These tags are not supported in newer versions of HTML.
Avoid using the elements: <font>, <center>, and <strike>, and the attributes: color and bgcolor.
The perfect solution for professionals who need to balance work, family, and career building.
More than 10 000 certificates already issued!
The HTML Certificate documents your knowledge of HTML.
The HTML5 Certificate documents your knowledge of advanced HTML5.
The CSS Certificate documents your knowledge of advanced CSS.
The jQuery Certificate documents your knowledge of jQuery.
The XML Certificate documents your knowledge of XML, XML DOM and XSLT.
The ASP Certificate documents your knowledge of ASP, SQL, and ADO.
The PHP Certificate documents your knowledge of PHP and SQL (MySQL).
Your message has been sent to W3Schools.