CSS @media scripting Property
Photo Credit to CodeToFun
π Introduction
The @media scripting
feature in CSS is used to apply styles based on the availability of scripting support (e.g., JavaScript) in the browser.
This can be useful for providing alternative styles for scenarios where scripting is disabled or unavailable, ensuring that your site remains accessible and functional.
π‘ Syntax
The syntax for the @media scripting
feature is similar to other media queries. You can define different styles depending on whether scripting is enabled or disabled.
@media (scripting: value) {
/* CSS rules */
}
Here, value can be one of the following:
- none: No scripting available (JavaScript disabled).
- initial-only: JavaScript is available only during page load but unavailable afterwards.
- enabled: Scripting is fully enabled.
π Property Values
- none: Applies styles when JavaScript is disabled or not available.
- initial-only: Applies styles when JavaScript is enabled initially but disabled later on (rare scenario).
- enabled: Applies styles when JavaScript is enabled in the browser.
ποΈ Default Value
There is no specific "default value" for @media scripting
, as it depends on the user's browser settings and whether JavaScript is enabled or disabled.
π Example Usage
π Basic Usage
In this example, we will display a message depending on whether JavaScript is enabled or disabled in the browser.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS @media scripting Example</title>
<style>
/* If JavaScript is disabled */
@media (scripting: none) {
.no-js-message {
display: block;
color: red;
font-size: 1.2em;
}
}
/* If JavaScript is enabled */
@media (scripting: enabled) {
.js-message {
display: block;
color: green;
font-size: 1.2em;
}
}
.js-message, .no-js-message {
display: none;
}
</style>
</head>
<body>
<h1>CSS @media scripting Example</h1>
<div class="no-js-message">JavaScript is disabled or not available in your browser.</div>
<div class="js-message">JavaScript is enabled in your browser.</div>
</body>
</html>
π₯οΈ Browser Compatibility
The @media scripting
property is supported in modern browsers, including Chrome, Firefox, Safari, and Edge. However, it is a good idea to test your styles across different environments to ensure they work as expected, especially when JavaScript is disabled.
π Conclusion
The @media scripting
property provides a way to tailor the appearance of your website based on the availability of scripting in the user's browser. This ensures that your website remains functional and user-friendly, even when JavaScript is disabled. Itβs a helpful tool for enhancing accessibility and providing a consistent user experience across various scenarios.
π¨βπ» Join our Community:
Author
For over eight years, I worked as a full-stack web developer. Now, I have chosen my profession as a full-time blogger at codetofun.com.
Buy me a coffee to make codetofun.com free for everyone.
Buy me a Coffee
If you have any doubts regarding this article (CSS @media scripting Property), please comment here. I will help you immediately.