HTML Styles – CSS

Now we have not given examples for everyone but will update soonCSS = Styles और Colors

Manipulating Text

Colors,  Boxes

Styling HTML with CSS

CSS stands for Cascading Style Sheets.

CSS describes how HTML elements should be displayed on screen, paper, or other media.

CSS saves a lot of work. It can control the layout of multiple web pages at once.

CSS can be added to HTML elements in 3 ways:

Inline – using the style attribute in HTML elements

Internal – using the <style> element in the <head> section

External – Using an external CSS file

The most common way to add CSS is by placing the styles in separate CSS files. However, here we’ll use inline and internal styling, as it’s easier to demonstrate, and easier for you to try yourself.

Suggestion: If you guys say, we would like to launch an app for CSS very soon. From where you will be able to learn a lot about CSS in our CSS Tutorial. ,

inline css

Inline CSS is used to apply a unique style to a single HTML element.

An inline CSS uses the style attribute of an HTML element.

This example will set the text color of the <h1> element to blue:

example

<h1 style=”color:blue;”>This is a blue heading</h1>

internal css

An internal CSS is used to define the style for an HTML page.

internal CSS is defined inside the <style> element in the <head> section of the HTML page:

example

<!DOCTYPE html>

<html>

<head>

<style>

body {background-color: powderblue;}

h1   {color: blue;}

p    {color: red;}

</style>

</head>

<body>

<h1>यह हैडिंग है </h1>

<p>यह पैराग्राफ है .</p>

</body>

</html>

External CSS

An external style sheet is used to define the style for many HTML pages.

With an , you can change the look of an entire web site, by changing one file! With an external style sheet, you can change the look of an entire web site by changing a single file!

To use an external style sheet, add a link to it in the <head> section of the HTML page:

Example

<!DOCTYPE html>

<html>

<head>

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

</head>

<body>

<h1>यह हैडिंग है</h1>

<p>यह पैराग्राफ है .</p>

</body>

</html>

An external style sheet can be written in any text editor. The file should not contain any HTML code, and should be saved with the .css extension.

Here’s what “styles.css” looks like:

body {

  background-color: powderblue;

}

h1 {

  color: blue;

}

p {

  color: red;

}

CSS Fonts

The CSS color property defines the text color to be used.

The CSS font-family property defines the font to be used.

The CSS font-size property defines the text size to be used.

Example

<!DOCTYPE html>

<html>

<head>

<style>

h1 {

  color: blue;

  font-family: verdana;

  font-size: 300%;

}

p  {

  color: red;

  font-family: courier;

  font-size: 160%;

}

</style>

</head>

<body>

<h1>यह हैडिंग है </h1>

<p>यह पैराग्राफ है .</p>

</body>

</html>

CSS Border

The CSS border property defines the border around the HTML element:

Example

p {

  border: 1px solid powderblue;

}

CSS Padding

The CSS padding property defines the padding (space) between the text and the border:

Example

p {

  border: 1px solid powderblue;

  padding: 30px;

}

CSS Margin

The CSS margin property defines the margin (space) outside the border:

Example

p {

  border: 1px solid powderblue;

  margin: 50px;

}

id Attribute

To define a for for a special element, to define a specific style, an id attribute is added to the element:

<p id=”p01″>I am different </p>

then define a style for the element with the specific id:

example

#p01 {

  color: blue;

}

Note: The ID of an element must be unique within a page, so an ID selector is used to select a unique element!

class attribute

To define a style for special types of elements, a class attribute is added to the element:

<p class=”error”>I am different </p>

Then define a style for an element with a specific class:

Example

p.error {

  color: red;

}

External References

External style sheets can be referenced with an absolute URL or a relative path to the current web page.

This example uses an absolute URL to link to the style sheet:

Example

<link rel=”stylesheet” href=”https://www.example.com/html/styles.css”>

This example links to a style sheet located in the HTML folder on the current Web site:

Example

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

This example links to a style sheet located in the same folder as the current page:

Example

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

Leave a Comment