The Wayback Machine - https://web.archive.org/web/20250128001843/https://www.geeksforgeeks.org/css-tutorial/
Open In App

CSS Tutorial

Last Updated : 28 Dec, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

CSS stands for Cascading Style Sheets. It is a stylesheet language used to style and enhance website presentation.

  • CSS is one of the main three components of a webpage along with HTML and JavaScript.
  • HTML adds Structure to a Webpage, JavaScript adds logic to it and CSS makes it visually visually appealing or stylish. It controls the layout of a web page i.e. how HTML elements will be displayed on a webpage.
  • CSS was released (in 1996), 3 years after HTML (in 1993). The main idea behind its use is, it allows the separation of content (HTML) from presentation (CSS). This makes websites easier to maintain and more flexible.
Webpage-In-Browser
Webpage in Browser - CSS Tutorial

How to Add CSS to HTML?

There are three different ways to add CSS styles to an HTML document, these are -

1. Inline CSS

Use the style attribute on the HTML element to add styles to the web page. It is used for small projects.

HTML
<!-- File name: index.html -->
<html>
<body>  
    <!-- Using Inline CSS -->
    <h3 style="text-align: center;">
      	Welcome To GFG
 	</h3>
  
    <p>CSS Tutorial - GeeksforGeeks</p>
</body>
</html>

2. Internal CSS

Place the CSS styles within a <style> tag inside the HTML file, usually inside the <head> section.

HTML
<!-- File name: index.html -->
<html>
<head>    
  	<!-- Using Internal CSS -->
    <style>
        h3 {
        	color: green;
        }
    </style>
</head>
<body>  
    <!-- CSS is applied here -->
    <h3>Welcome To GFG</h3>
  
    <p>CSS Tutorial - GeeksforGeeks</p>
</body>
</html>

3. External CSS

Create a separate CSS file with a .css extension and link this file to your HTML file using the <link> tag.

HTML
<!-- File name: index.html -->
<html>
<head>
  	<!-- Importing External CSS -->
    <link rel="stylesheet" href="style.css" /> 
</head>
<body>
    <p>CSS Tutorial - GeeksforGeeks</p>
</body>
</html>
CSS
/* Write CSS Here *//* External CSS */
/* File name: style.css */
p {
  	text-align: center;
}

CSS-Tutorial
Let's dive into the world of colors with CSS- CSS Tutorial

Introduction to Modern CSS

This section covers the basic understanding of CSS, its advantages and disadvantages.

CSS Fundamentals

This section covers the fundamental topics of CSS

CSS Selectors

This Section contains all the information about all the simple selectors in CSS

CSS Combinators

This Section contains all the information about combinatory selectors in CSS

CSS Layout Management

This Section contains all the information about various layouts in CSS

Styling Techniques in CSS

This Section contains all the information about various styling techniques in CSS

Logic Implementations in CSS

This Section Covers all the mathematical logic that can be applied in CSS.

CSS Responsive Design and Media Queries

This Section contains all the designing techniques in CSS used for various use cases

CSS Preprocessors

This Section contains information about the preprocessors used in CSS.

Advanced CSS Topics

This Section contains various information about advanced topics in CSS

CSS Online Quizzes

To achieve a solid understanding of CSS, it’s essential to engage with CSS quizzes and MCQs. These CSS quizzes can enhance your ability to solve similar questions and improve your problem-solving skills.

Here are some quiz articles related to CSS 3:

CSS Practical projects for beginners

The theoretical knowledge is not enough to understand CSS. So, it is required to work on some real life projects to learn CSS easily. Working on such HTML & CSS projects will test your CSS knowledge and you will get some hands-on experience.

Below are some HTML and CSS projects for better understanding.

CSS Interview Preparation Questions

CSS Frameworks

CSS frameworks are a collection of pre-written CSS files (and sometimes JavaScript components) that offer reusable code for common tasks such as buttons, grids, forms, and navigation menus.

These CSS frameworks provide a set of standardized, reusable components and a predefined structure, allowing developers to create responsive and aesthetically pleasing websites with reduced effort.

CSS Frameworks

Other Resources

CSS Versions

  • CSS1: The foundation, released in 1996, introduced basic styling capabilities for fonts, colors, and margins.
  • CSS2: Expanded in 1998, adding positioning elements, pseudo-classes, and improved layout options.
  • CSS 2.1: Further refinements in 2004, including improvements to inheritance and box model properties.
  • CSS3: Introduced from 2001 onwards, CSS3 isn't a single version but a collection of modules adding features like animations, media queries, and web fonts. It's constantly evolving.

Why learn CSS?

1. Enhance Visual Appeal: CSS allows you to style your web pages, making them visually appealing and engaging. Here’s why it matters:

  • User Experience (UX): Well-designed websites attract and retain users. CSS enables you to create beautiful layouts, choose fonts, and apply colors that resonate with your audience.

2. Responsive Design: In today’s mobile-first world, responsive design is crucial. CSS empowers you to:

  • Media Queries: Adapt your layout based on screen size (desktop, tablet, mobile).
  • Flexbox and Grid: Create flexible, adaptive designs that look great on any device.

3. SEO Benefits: CSS indirectly impacts your site’s SEO. Here’s how:

  • Page Load Speed: Well-organized CSS files load faster, improving user experience. Google considers page speed as a ranking factor.
  • Structured Content: Properly styled HTML (thanks to CSS) enhances readability for search engines and users.
  • Mobile Friendliness: Responsive CSS ensures your site performs well on mobile devices, positively affecting rankings.

4. Efficient Maintenance: CSS promotes clean code and separation of concerns:

  • Modularity: Separate CSS files allow easy updates without affecting other parts of your site.
  • Consistency: Apply styles consistently across your site using classes and IDs.

5. Career Opportunities: Learning CSS opens doors to various roles:

  • Front-End Developer: Mastering CSS is essential for front-end development.
  • Web Designer: CSS skills are fundamental for creating stunning web layouts.
  • Full-Stack Developer: Understanding CSS complements back-end skills.

CSS Tutorial - FAQ's

What is CSS?

CSS (Cascading Style Sheets) is a stylesheet language used to control the presentation and layout of HTML elements on a webpage. It defines styles such as colors, fonts, spacing, and positioning, enhancing the visual appearance of web content.

What is the Full Form of CSS?

CSS stands for Cascading Style Sheets. It is a style sheet language used to describe the presentation and formatting of a document written in HTML or XML.

What are the types of CSS?

There are three types of CSS: Inline CSS, which is applied directly within an HTML element; Internal CSS, written inside the <style> tag in the HTML document's head; and External CSS, linked through a separate .css file using the <link> tag.

Use the <link> element within the <head> section of your HTML document. Example: <link rel="stylesheet" type="text/css" href="styles.css">

What is the purpose of the 'box model' in CSS?

The box model is a fundamental concept in CSS that describes the layout of elements. It consists of content, padding, border, and margin, which collectively determine the size and spacing of an element.

How can I center an element horizontally and vertically in CSS?

To center horizontally, use margin: auto; on the element. For vertical centering, consider using Flexbox (display: flex; align-items: center; justify-content: center;) or Grid (display: grid; place-items: center;).

What is the difference between 'margin' and 'padding' in CSS?

Margin is the space outside an element, creating space between the element and its surrounding elements. Padding is the space inside an element, creating space between the element's content and its border.

How do media queries contribute to responsive design in CSS?

Media queries allow developers to apply styles based on characteristics such as screen width, height, or device orientation. They are crucial for creating responsive designs that adapt to different devices and screen sizes.


Similar Reads

three90RightbarBannerImg