CSS Tutorial Learn Cascading Style Sheets for Beginners

This CSS tutorial (CSS3 tutorial) covers both basic and advanced CSS concepts , including layout techniques and responsive design. It is suitable for beginners learning web design and for professionals who want to strengthen their front-end development skills.

Relationship Between HTML and CSS

HTML serves as a markup language crucial for establishing the fundamental layout of a webpage, encompassing elements like headers, text blocks, visuals, and hyperlinks. Nevertheless, HTML does not possess the capability to dictate the visual style of these components. Webpages crafted solely with HTML exhibit a simplistic appearance devoid of intricate design, color schemes, and styling.

CSS collaborates with HTML to format web content. This enables developers to segregate content from styling, leading to more organized code and easier maintenance.

What CSS Is Used For?

CSS is essential for managing the design, color scheme, typography, margins, and positioning of websites. It plays a crucial role in developing adaptable layouts that can adjust to various screen dimensions such as smartphones, tablets, and computers. Additionally, CSS facilitates the incorporation of smooth transitions, dynamic animations, and appealing visual enhancements that elevate the overall user interaction.

What is CSS?

The major points of CSS are given below:

  • CSS stands for Cascading Style Sheet.
  • CSS is a widely used language on the web.
  • CSS helps web designers to apply style to HTML tags .
  • CSS is utilized to make a responsive website.
  • How does CSS help to improve a website?

We will understand this by using an illustration.

Let us write the HTML code:

Example

Example

<p>Hello Everyone!</p>

Output:

The content appears unadorned without CSS. Next, we will apply CSS to improve the appearance of the text.

Let's compose the CSS code within the designated <style> tag:

Example

Example

<!DOCTYPE html>

<html>

  <head>

    <title>CSS</title>

    <style>

    body {

        background-color: rgb(249, 207, 252);

    }

    p {

        font-family: sans-serif;

        font-size: 20px;

        color: rgb(24, 4,105);

        font-weight: bold;

    }

    </style>

  </head>

  <body>

      <p>Hello Everyone!</p>

  </body>

</html>

Output:

Now that the CSS code has been written, the text is now displaying in a variety of colors and larger font sizes. Additionally, the background has also been enhanced with vibrant colors. This showcases how CSS enhances the appearance of a website, resulting in a more visually appealing design. This is the transformative power of CSS.

Why learn CSS?

  • Creating Beautiful Websites: The structure of the web page is created using HTML but if you want to make a colourful website then CSS is used. It controls the visual style of the page. It adds colors, fonts, animations and more to HTML tags.
  • Making Responsive Websites: CSS is used to make responsive websites which means it makes mobile-friendly design that adapts to all sizes of screens such as phones, laptops, tablets, etc.
  • Customizing Anything: It is utilized to customize web pages like creating a dark theme, stylish menus, animated text and more.
  • Boosting your Career: If you want to be a web developer or UI/UX designer then you must learn CSS because it is a must-have skill in the tech world.
  • Applications of CSS

Styling Websites: Cascading Style Sheets (CSS) are employed to customize the appearance of HTML elements on websites, including aspects like font styles, background colors, text colors, layout arrangements, border designs, spacing configurations, animations, and more. CSS plays a pivotal role in managing and improving the visual appeal of a website, ensuring it is dynamic and captivating.

CSS plays a vital role in adapting web pages to various screen sizes like mobile, laptop, tablet, etc. CSS media queries are employed to ensure web pages are responsive across different devices, enhancing the user experience.

CSS plays a crucial role in producing seamless effects on a webpage to enhance interactivity, even in the absence of JavaScript. It is instrumental in generating effects such as hover effects, animated button clicks, fade-ins, and more.

Managing a website: CSS plays a crucial role in efficiently handling and preserving the website's style. It allows for the creation of a distinct CSS file apart from the HTML file. In case there is a need to modify the website's design in the future, adjustments like updating font styles, background colors, etc., can be made in the CSS file, thereby saving time and effort.

By enabling alterations to style without impacting the HTML structure, CSS contributes to enhancing web accessibility. It facilitates improvements like enhancing readability, adjusting font sizes, and more. CSS plays a crucial role in ensuring websites are navigable for individuals with disabilities by providing features such as alternative text for images and color contrast options.

Custom Themes: CSS enables the development of personalized themes like light or dark modes, offering users the flexibility to customize the visual style of the website.

Social Networking: CSS plays a crucial role in crafting the design of social networking platforms. It enables the creation of share buttons and preview feeds, enhancing the visual appeal of the pages. Prominent social media platforms like Twitter, Facebook, Instagram, and others have already leveraged CSS for this purpose.

CSS plays a crucial role in enhancing the visual appeal of e-commerce platforms, including product pages, shopping carts, and checkout forms. By leveraging CSS, developers can craft a sleek and professional interface that instills confidence in users. Furthermore, CSS is instrumental in designing elements like eye-catching discounts and prominent buy buttons, effectively capturing the attention of potential customers.

Framework Integration: CSS is compatible with various frameworks like Tailwind CSS, Bootstrap, Materialize, and others. These frameworks come equipped with pre-existing classes and tools that facilitate the efficient development of adaptable websites.

CSS Versions

There are several versions of CSS . They are as follows:

  • CSS1 : It is the first version, which was introduced on December 17, 1996 . The features it brought were basic styling properties for font, texts and the concepts of selectors.
  • CSS2 : It is the second version, which was introduced on May 12, 1998. The features it brought were display property, pseudo-classes, pseudo-elements, etc.
  • 2.1 : It is the third version, which was introduced on June 7, 2011 . The features it brought were colour properties, e.g., rgba, hsl. This version standardized box model properties and improved cross-browser compatibility.
  • CSS3 : The fourth version, which was introduced at the start of 1999 . It is the latest version. It brought the collection of modules, such as Selector, Box-Model, Backgrounds and Borders, 2DTransformations, Grid Layout, etc.
  • CSS4 (Upcoming): CSS4 is an upcoming version. The particular modules and features are in development. It may add some improvement to the existing modules and new features.
  • CSS5 (Planned): It is not officially announced but represents the future development of CSS. It will include further enhancements and capabilities.
  • Types of CSS

There exist three primary categories of CSS. These include:

  • Internal CSS: It is integrated within the HTML file using the <style> tag in the head section. This type of CSS applies styles to the entire HTML document.
  • External CSS: It is stored in a separate CSS file and linked to the HTML file using the <link> tag. External CSS allows for the consistent styling of multiple HTML files.
  • Inline CSS: This type is directly applied to an HTML element within the HTML file using the style attribute. Inline CSS holds the highest precedence in styling hierarchy.

Example:

In this instance, we will apply color to the text using inline CSS.

Code:

Example

Example

<!DOCTYPE html>

<html>

<head>

<title>My Page</title>

</head>

<body>

<h1 style="color: red;">Hello, CSS!</h1>

</body>

</html>

Output:

  1. Internal CSS : The code of internal CSS is written in the HTML file by the developers. The <style> tag is utilized by the developer to define it. In the <head> tag, the <style> tag is defined, and within that, we write CSS code.

Example :

In this instance, we will assign color and font-family to the text using Internal CSS.

Code:

Example

Example

<!DOCTYPE html>

<html>

<head>

<title>My Page</title>

<style>

   h1{

    color: blue;

    font-family: Cursive;

   } 

</style>

</head>

<body>

<h1>Hello, CSS! </h1>

</body>

</html>
  1. In external CSS, a distinct file is generated to specify the CSS externally with a .CSS extension. Developers employ the <link> tag to connect this file to the HTML file. External CSS is the preferred approach for defining CSS in extensive projects because it simplifies the process of managing and revising the style consistently across multiple pages.

Example:

In this example, we are going to apply color and font-family styles to the text using External CSS. The connection between HTML and CSS will be established using the <link> tag.

HTML Code File:

Example

Example

<!DOCTYPE html>

<html>

<head>

<title>My Page</title>

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

</head>

<body>

<h1>Hello, CSS! </h1>

</body>

</html>

styles.css File:

Example

h1{

    color: green;

    font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;

}

Output:

Note: The style of inline CSS has a higher priority among the three. The internal CSS has more priority than the external CSS.

CSS Properties

CSS attributes serve as the foundation of web development. They are employed to specify the arrangement or design of the webpage, regulating the functionality of HTML components.

The list of some basic properties is given below:

Text Properties

Property Descriptions
color It sets the text color.
text-align It horizontally aligns the text. e.g., left, right, center, justify.
line-height It is utilized by the developer to give the gap between lines.
letter-spacing It is utilized by the developer to give the spaces between characters.
text-decoration It is utilized by the developer to decorate the text e.g., none, underline, etc.
text-transform It is utilized by the developer to define the uppercase and lowercase letters in a text.

Font Properties:

Property Descriptions
font It is a shorthand property which is utilized by the developer to give all the font-properties in one declaration.
font-family It is utilized by the developer to give the font family.
font-size It is utilized by the developer to give the size to text.
font-style It is utilized by the developer to style the text.
font-weight It is utilized by the developer to specify the weight of a font such as thickness and boldness.

List Properties:

Property Descriptions
list-style It is a shorthand property which is utilized to set all properties in one declaration.
list-style-type It is utilized by the developer to define the type of list-item, e.g., none, disc, square, circle, etc.
list-style-position It is utilized to define the position of the list-item markers.
list-style-image It is utilized by the developer to define an image as the list-item marker.

Border Properties:

Property Descriptions
border It is a shorthand property for border width, style and color. It is utilized by the developer to set the border properties in one declaration.
border-width It is utilized to give width to all borders.
border-color It is utilized by the developer to give the color to all the borders of a box.
border-style It is utilized by the developer to style all borders of the box.
border-bottom It is a shorthand property for bottom border width, style and color utilized by the developer to set the bottom border properties in one declaration.
border-bottom-width It is utilized to give width to bottom border.
border-bottom-color The developer makes use of it to give the color to the bottom border.
border-bottom-style The developer makes use of it to style the bottom border.
border-left It is a shorthand property left border width, style and color utilized by the developer to set all the properties of the left-border in one declaration.
border-left-width It is utilized to give width to left border.
border-left-color It is utilized by the developer to give the color to the left border.
border-left-style It is utilized by the developer to style the left border.
border-right It is a shorthand property for right border width, style and color utilized by the developer to set all the right border properties in one declaration.
border-right-width It is utilized to give width to right border.
border-right-color The developer makes use of it to give the color to the right-border.
border-right-style It is utilized by the developer to style the right border.
border-top It is a shorthand property for top border width, style and color utilized by the developer to set all the top border properties in one declaration.
border-top-width It is utilized to give width to top border.
border-top-color The developer makes use of it to give the color to the top border.
border-top-style It is utilized by the developer to style the top border.

Career Opportunity of learning CSS

Upon mastering CSS, numerous career paths open up within the realm of web development and design. CSS serves as a fundamental competency in front-end development, making it essential for individuals aspiring to pursue careers in front-end development, web design, UX/UI design, email development/design, and related fields.

CSS is applied in frameworks and libraries such as React.js, Vue.js, and others. The current trend emphasizes the importance of user-friendly digital interactions. As a result, employers are now looking for candidates who can design and enhance interfaces, highlighting the crucial role CSS plays in web development.

Conclusion:

In this tutorial, we have explored CSS thoroughly. We have discussed different aspects including the different versions of CSS, the three categories of CSS, its attributes, and potential career paths. CSS stands out as a crucial skill when it comes to building a front-end website.

FAQs:

Some commonly encountered inquiries are presented here:

  1. What sets apart id and class from each other?

The contrast between id and class lies in their distinct functionalities: an id serves as the exclusive identifier of an element, whereas a class can be assigned to several elements, enabling the application of uniform styles to grouped elements.

Now, let's delve into the topic of CSS Selectors.

It is employed to choose elements according to their name, identification, attributes, class, tags, and other properties.

  1. Could you explain the concept of the Box model?

Every element in HTML is wrapped around a box model . A box model consists of the following:

  • Content: It is the content, g., text, images etc .
  • Padding: It is a whitespace around the content.
  • Border: It is around the padding.
  • Margin: It is around the border.
  1. How can you integrate CSS into an HTML Page?

There are three methods to integrate CSS into an HTML page. They are as follows:

  • Inline CSS
  • Internal CSS
  • External CSS
  1. How can you make a website responsive?

CSS Media queries are employed to ensure a website's responsiveness. The format is as follows:

Example

@media media-type and (condition) {

    // CSS Code

}

Input Required

This code uses input(). Please provide values below: