cbse cs logo


CSS and HTML class 10

CSS stands for Cascading Style Sheets. It is a style sheet language which is used to describe the look and formatting of a document written in markup language. It provides an additional feature to HTML. It is generally used with HTML to change the style of web pages and user interfaces. 
CSS is used along with HTML and JavaScript in most websites to create user interfaces for web applications and user interfaces for many mobile applications.

With CSS, you 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 are to be used, different displays for different devices and screen sizes, and much more!


These are the three major benefits of CSS:

1) Solves a big problem

Before CSS, tags like font, color, background style, element alignments, border and size had to be repeated on every web page. This was a very long process. For example: If you are developing a large website where fonts and color information are added on every single page, it will be become a long and expensive process. CSS was created to solve this problem. It was a W3C recommendation.

2) Saves a lot of time

CSS style definitions are saved in external CSS files so it is possible to change the entire website by changing just one file.

3) Provide more attributes

CSS provides more detailed attributes than plain HTML to define the look and feel of the website.



Difference between HTML and CSS:

1. HTML is a markup language used to define a structure of a web page. CSS is a style sheet language used to style the web pages by using different styling features.
2. It consists of tags inside which text is enclosed. It consists of selectors and declaration blocks.
3. HTML doesn’t have further types. CSS can be internal or external depending upon the requirement.
4. We cannot use HTML inside a CSS sheet. We can use CSS inside an HTML document.
5. HTML is not used for presentation and visualization. CSS is used for presentation and visualization.
6. HTML has comparatively less backup and support. CSS has comparatively higher backup and support.
7. HTML doesn’t allow animations and transitions. CSS allows animation and transitions which helps to improve the UI.
8. HTML files are saved with .htm or .html extension. CSS files are saved with .css extension.



Using CSS

CSS can be added to HTML documents in 3 ways:

  • Inline – by using the style attribute inside HTML elements
  • Internal – by using a <style> element in the <head> section
  • External – by using a <link> element to link to an external CSS file


Inline CSS:

Inline CSS is used to apply CSS in a single element. It can apply style uniquely in each element.

To apply inline CSS, you need to use style attribute within HTML element. We can use as many properties as we want, but each property should be separated by a semicolon (;).


  1. <h3 style=”color: red;  
  2.             font-style: italic;  
  3.             text-align: center;  
  4.             font-size: 50px;  
  5.             padding-top: 25px;”>Learning HTML using Inline CSS</h3>  



Internal CSS

An internal CSS is used to define a style for a single HTML page.

An internal CSS is defined in the <head> section of an HTML page, within a <style> element.

The following example sets the text color of ALL the <h1> elements (on that page) to blue, and the text color of ALL the <p> elements to red. In addition, the page will be displayed with a “powderblue” background color: 


<!DOCTYPE html>
body {background-color: powderblue;}
h1   {color: blue;}
p    {color: red;}


<h1>This is a heading</h1>
<p>This is a paragraph.</p>




External CSS

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:


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

<h1>This is a heading</h1>
<p>This is a paragraph.</p>


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

Here is what the “styles.css” file looks like:


body {
background-color: powderblue;
h1 {
color: blue;

color: red;
error: Content is protected !!