How To Disable Text Selection Highlighting In The Browsers Using CSS?

I received a question from a developer who was facing a challenge while working on a tribute project. They had already completed the HTML part and were trying to integrate CSS, but the browser wasn’t fetching the styles. Despite using editors like VSCode and Atom, the issue persisted, so they reached out for help. In this post, I will walk through the common mistakes that could cause this problem and provide a simple solution.

Common Error in Linking CSS:

A common error might happen when the link to the CSS file in the HTML document is incorrect. Here’s an Error in Linking CSS:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tribute Page</title>
<!-- Link to CSS file -->
<link rel="stylesheet" href="style.css"> <!-- Possible mistake: wrong file path -->
</head>
<body>
<h1>This is my Tribute Page</h1>
</body>
</html>

The issue: The CSS file style.css is not being loaded because the file path in the href attribute is incorrect or misplaced. This can happen if:

  • The CSS file is in a different folder.
  • The file name or extension is incorrect.
  • There is a typo in the file path.

Fixed Solution:

  1. Check the CSS file path: Ensure that your style.css file is located in the same directory as your HTML file. If the file is in a different folder, you need to include the correct path.

For example, if your CSS file is inside a css folder, update the link like this:

<link rel="stylesheet" href="css/style.css">
  1. Ensure file extensions are correct: Make sure your file is named style.css and not style.html or any other extension.
  2. Browser cache: Sometimes, the browser caches the old version of the files, causing new changes to not appear. Try clearing the browser cache or performing a hard refresh (Ctrl + F5 or Cmd + Shift + R on Mac).
  3. File permissions: Ensure your CSS file is not restricted by permissions and can be accessed by the browser.

Conclusion

This type of issue is often related to simple file path or naming errors. Double-check your directory structure, and once the path is correct, your CSS should load without issues.

Related blog posts