Home >Web Front-end >HTML Tutorial >How to link html and css
The method to link an HTML page with a CSS file is to create a CSS file and define style rules. Add a <link> tag to the <head> section of the HTML page to specify the path to the CSS file. Use the rel="stylesheet" attribute to specify the link type and the href="mystyle.css" attribute to specify the CSS file path.
How to link HTML with CSS
In order to link HTML pages with CSS files, you can use <link>
Tag:
<link rel="stylesheet" href="mystyle.css">
This tag is placed on the HTML page <head>
section.
Detailed steps:
Create CSS file:
mystyle.css
. Define CSS style:
mystyle.css
file, write the CSS style Rules to style HTML elements. For example: <code class="css">body { font-family: sans-serif; } h1 { font-size: 2em; color: blue; }</code>
Link the CSS file with the HTML page:
< of the HTML page Within the head>
section, add the <link>
tag: <code class="html"><head> <link rel="stylesheet" href="mystyle.css"> </head></code>
rel="stylesheet"
attribute specifies that this is a Style sheet file. href="mystyle.css"
property specifies the path to the CSS file. Note:
The tag must be placed in
<head> section because the browser reads the CSS before rendering the HTML page.
tag for each file.
The above is the detailed content of How to link html and css. For more information, please follow other related articles on the PHP Chinese website!