02 / 03

What are the different ways in which we can include CSS in our HTML file?

Difficulty: 4/10
inline styles, internal stylesheet, external stylesheet

CSS can be added to HTML in several ways depending on how you want to structure and maintain your styles. Each method has its use case, from quick inline styling to full-scale external stylesheets.

Different Ways to Include CSS
  1. 1

    Inline CSS: Added directly within an HTML element using the 'style' attribute.

  2. 2

    Internal CSS: Written inside a <style> tag within the <head> section of the HTML document.

  3. 3

    External CSS: Written in a separate .css file and linked to the HTML document using a <link> tag in the <head>.

  4. 4

    Imported CSS: Brought into another CSS file using the '@import' rule.

Examples of Each Method

Scenario Questions

0-2 years experience

  1. 1You need to make a single paragraph text red on a static page. How would you add the CSS directly in the HTML?
  2. 2If you want all headings on the page to share the same font, which inclusion method would you pick and why?
  3. 3Show me the HTML tag you would use to link an external stylesheet called styles.css.

2-5 years experience

  1. 1Your teammate added a <link> to a stylesheet but the styles aren't applying. Walk me through how you'd debug the issue.
  2. 2We have a component that sometimes needs dynamic colors based on user input. Which CSS inclusion technique would you use and what trade‑offs does it have?
  3. 3Explain why using inline styles for layout caused the page to load slower than expected.

5-8 years experience

  1. 1Our web app has critical above‑the‑fold CSS that must load fast, but also large shared styles. How would you structure the inclusion methods to optimise load time and caching?
  2. 2Design a theming approach for a large SPA that allows per‑brand customisation while keeping CSS maintainable. Which inclusion strategies would you combine?
  3. 3What security considerations (e.g., CSP) arise when using @import versus <link> in a multi‑tenant environment?

8+ years experience

  1. 1We are migrating a legacy monolithic CSS codebase to a component‑scoped CSS‑in‑JS solution across several teams. How would you plan the transition while preserving existing styling and minimizing disruption?
  2. 2Describe a company‑wide policy for CSS inclusion that balances performance, developer experience, and long‑term maintainability. How would you enforce it across CI/CD pipelines?
  3. 3In a micro‑frontend architecture, how do you prevent style leakage and conflicts when each team may choose different inclusion methods?

Follow-up Questions

  • What performance differences do you see between inline, internal, and external CSS?
  • How does CSS specificity interact with these inclusion methods?
  • Can you give an example where you would deliberately choose inline styles over an external file?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.