Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
@daviddarnes/contrast-details
Advanced tools
A Web Component to display the contrast ratio and level of two colours using CSS custom properties
contrast-details
A Web Component to display the contrast ratio and level of two colours using CSS custom properties
Demo | Custom template demo | Further reading
General usage example:
<script type="module" src="contrast-details.js"></script>
<contrast-details
style="--foreground: #444; --background: #ccc"
></contrast-details>
<contrast-details
style="--foreground: #444; --background: #613fe8"
></contrast-details>
Example using inherited values:
<script type="module" src="contrast-details.js"></script>
<div style="--foreground: #444">
<contrast-details style="--background: #ccc"></contrast-details>
<contrast-details style="--background: #ffffff"></contrast-details>
<contrast-details style="--background: #613fe8"></contrast-details>
</div>
Example using level
attribute for styling
<style>
contrast-details[level^="aa"] [data-key="level"]::after {
content: " ✅";
}
contrast-details[level="fail"] [data-key="level"]::after {
content: " ❌";
}
</style>
<script type="module" src="contrast-details.js"></script>
<contrast-details
style="--foreground: #444; --background: #ccc"
></contrast-details>
<contrast-details
style="--foreground: #444; --background: #613fe8"
></contrast-details>
Example using a custom template:
<script type="module" src="contrast-details.js"></script>
<template id="contrast-details-template">
<p>
Contrast: <span data-key="ratio"></span> –
<span data-key="level"></span>
</p>
</template>
<contrast-details
style="--foreground: #444; --background: #ccc"
></contrast-details>
<contrast-details
style="--foreground: #444; --background: #613fe8"
></contrast-details>
This Web Component allows you to:
level
attribute selector to style elements differently depending on aaa
, aa
and fail
gradesYou have a few options (choose one of these):
npm install @daviddarnes/contrast-details
Make sure you include the <script>
in your project (choose one of these):
<!-- Host yourself -->
<script type="module" src="contrast-details.js"></script>
<!-- 3rd party CDN, not recommended for production use -->
<script
type="module"
src="https://www.unpkg.com/@daviddarnes/contrast-details@1.1.0/contrast-details.js"
></script>
<!-- 3rd party CDN, not recommended for production use -->
<script
type="module"
src="https://esm.sh/@daviddarnes/contrast-details@1.1.0"
></script>
With thanks to the following people:
FAQs
A Web Component to display the contrast ratio and level of two colours using CSS custom properties
The npm package @daviddarnes/contrast-details receives a total of 2 weekly downloads. As such, @daviddarnes/contrast-details popularity was classified as not popular.
We found that @daviddarnes/contrast-details demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.