CSS (Cascading Style Sheets) allows for flexibility in how you organize and apply styles to your web pages. Here are the various types of CSS files and their usages:
An external CSS file is a separate .css
file that contains all the styles for your website. It's the most common way to apply CSS because it keeps the HTML clean and separates content from presentation.
Usage:
Internal CSS is defined within a <style>
tag in the <head>
section of the HTML document. This method is useful for single-page websites or when you need to apply styles that are unique to a specific page.
Usage:
Inline CSS is applied directly to the HTML elements using the style
attribute. This method is mainly used for quick, specific changes but is not recommended for larger projects due to its lack of maintainability.
Usage:
CSS preprocessors like Sass (Syntactically Awesome Style Sheets) and LESS (Leaner Style Sheets) allow you to write more complex, maintainable, and reusable CSS code by providing advanced functionalities like variables, nesting, mixins, and more. The preprocessed code is then compiled into standard CSS.
Usage:
Sass (.scss or .sass files):
LESS (.less files):
CSS-in-JS is a styling approach where CSS is written within JavaScript files. This method is popular in frameworks like React, allowing for component-level styles and dynamic styling based on component state.
Usage:
Styled-components (React):
JSS (JavaScript Style Sheets):
CSS frameworks like Bootstrap, Tailwind CSS, and Materialize provide pre-written CSS files that can be incorporated into your project to enable ready-made, responsive, and utility-based designs.
Usage:
Bootstrap:
Tailwind CSS:
External CSS: Promotes reusability and maintainability, but can result in an additional HTTP request.
Internal CSS: Good for one-off