CSS Tutorial

External CSS

 

An external style sheet in CSS is a separate file containing styles that can be linked to multiple HTML documents. This separation of styles from HTML content allows for better organization, easier maintenance, and consistent styling across multiple pages.

Here’s how you can create and use an external style sheet in CSS:

Create a CSS File: Create a new text file and save it with a .css extension. For example, you could name it styles.css. This file will contain your CSS rules.

/* styles.css */

Link the CSS File to HTML: In your HTML file, you need to link the external style sheet. Add the following line within the <head> section of your HTML document.

h1 {

    color: #0066cc;

}

/* Add more styles as needed */

Link the CSS File to HTML: In your HTML file, you need to link the external style sheet. Add the following line within the <head> section of your HTML document.

<!DOCTYPE html>

<html >

<head>

    <link rel=”stylesheet” href=”styles.css”>

    <title>Your Page Title</title>

</head>

<body>

    <!– Your HTML content goes here –>

</body>

</html>

The href attribute in the <link> tag should point to the location of your CSS file.

Apply Styles: Now, any styles defined in your styles.css file will be applied to the HTML elements of the linked HTML document.

<!– Your HTML content goes here –>

<h1>This is a Heading</h1>

<p>This is a paragraph of text.</p>

The styles defined in styles.css(css file) will be applied to the corresponding HTML elements.

Using an external style sheet provides a clean and modular way to manage styles across multiple pages. If you need to make changes, you can do so in one central location (the CSS file) and have those changes reflected across all linked HTML documents.

EXTERNAL CSS file with HTML Example

1)mystyle.css(save this file with name mystyle.css)

body {

    background-color: blue;

}

h1 {

    color: navy;

    margin-left: 20px;

}

2)External.html(save this file with name external.html)

<head>

<link rel=”stylesheet” type=”text/css” href=”mystyle.css”>

</head>

<body>

    <h1>XCnotes.com</h1>

</body>

Run—–external.html

Recommended Posts

C++ Programming

Visibility modes in C++

In C++, visibility modes refer to the accessibility of class members (such as variables and functions) from different parts of a program. C++ provides three visibility modes: public, private, and protected. These modes control the access levels of class members concerning the outside world and derived classes. Public: Members declared as public are accessible from […]

Rekha Setia 
C++ Programming

Inheritance in C++

In C++, inheritance is a fundamental concept of object-oriented programming (OOP) that allows you to create a new class based on an existing class, known as the base or parent class. The new class is called the derived or child class. Inheritance facilitates code reuse and supports the creation of a hierarchy of classes. There […]

Rekha Setia 
C++ Programming

C++ Classes and Objects

In C++, classes and objects are fundamental concepts that support object-oriented programming (OOP). Here’s a brief overview of classes and objects in C++: Classes: In C++, a class is a user-defined data type that allows you to encapsulate data members and member functions into a single unit. Classes are the building blocks of object-oriented programming […]

Rekha Setia 

Leave A Comment