- CSS stands for Cascading Style Sheets. It can control the layout of multiple web pages all at once.
-
It is used to format the layout of a webpage. it can control the color, font, the size of text, the spacing between elements, how elements
are positioned and laid out, what background images or background colors to be used, different displays for different devices and screen sizes, and many more.
- Three types to give a CSS to HTML Document.
- Inline css
- Internal css
- External css
- The most common way to add CSS, is to keep the styles in external CSS files.
-
An inline CSS is used to apply a unique style to a single HTML element, inline CSS uses the style attribute of an HTML element, The following
example sets the text color of the <h1> element to blue, and the text color of the <p> element to red.
- Example
<p style="color:blue;">A paragraph.</p>
Output:
-
Internal CSS is used to define a style for a single HTML page. Internal CSS is defined in the <head> section of an HTML page, within a
<style> element.
- Example
<!DOCTYPE html>
<html>
<head>
<style>
body
{
background-color: yellow;
}
p
{
color: blue;
}
</style>
</head>
<body>
<p>a paragraph.</p>
</body>
</html>
-
An external style sheet is used to define the style for many HTML pages. To use an external style sheet, add a link to it in the <head>
section of each HTML page.
- Example
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
</head>
<body>
<p>a paragraph.</p>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
</head>
<body>
<p>a paragraph.</p>
</body>
</html>
Style.css
body {
background-color: yellow;
}
p {
color: blue;
}
Output:
- External style sheets can be referenced with a full URL or with a path relative to the current web page.
<link rel="stylesheet" href="https://phpcoderspoint.com/css/style.css">