{"id":22963462,"url":"https://github.com/kettek/css-audio","last_synced_at":"2025-08-24T06:35:46.099Z","repository":{"id":95261721,"uuid":"124290254","full_name":"kettek/css-audio","owner":"kettek","description":"CSS add-on library for audio playback and control","archived":false,"fork":false,"pushed_at":"2023-01-05T23:22:47.000Z","size":39,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-01T18:57:34.941Z","etag":null,"topics":["audio","css","css3","css3-selectors","html","html-css","html5-audio","javascript"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kettek.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-03-07T20:25:10.000Z","updated_at":"2025-02-19T08:37:34.000Z","dependencies_parsed_at":"2023-08-28T23:46:59.484Z","dependency_job_id":null,"html_url":"https://github.com/kettek/css-audio","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/kettek/css-audio","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kettek%2Fcss-audio","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kettek%2Fcss-audio/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kettek%2Fcss-audio/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kettek%2Fcss-audio/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kettek","download_url":"https://codeload.github.com/kettek/css-audio/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kettek%2Fcss-audio/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270204689,"owners_count":24544675,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-13T02:00:09.904Z","response_time":66,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["audio","css","css3","css3-selectors","html","html-css","html5-audio","javascript"],"created_at":"2024-12-14T19:35:20.469Z","updated_at":"2025-08-13T07:34:39.568Z","avatar_url":"https://github.com/kettek.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# css-audio\n**This software should be considered as both *alpha* and a curiosity.**\n\n## What is css-audio?\n**css-audio** is an add-on mechanism for adding audio playback and control to elements in Web documents.\n\nAlthough the author has specific uses for it in internal software projects, it is largely a curiosity created because it could be created. Enhancements, rewrites, or reimaginings are encouraged.\n\n## How does it work?\n**css-audio** works by using CSS custom properties with JavaScript to manage changes in these properties.\n\nA brief example, to add a sound to a button that triggers on click, would be:\n\n    button {\n      --audio-src: url('click.ogg');\n    }\n    button:active {\n      --audio-state: playing;\n    }\n\n\n## Basic Usage\nAdd the following to your HTML `\u003chead\u003e`:\n\u003e    \u0026lt;script type='text/javascript' src='//kettek.net/s/css-audio/css-audio-LATEST.min.js'\u003e\u0026lt;/script\u003e\n\u003e    \n\u003e    \u0026lt;script type='text/javascript'\u003ewindow.addEventListener('load', function() { KTK.CSSA.init(); })\u0026lt;/script\u003e\n\nThereafter you can add a stylesheet to the document head defining your *Audio Properties* and any accompanying HTML elements to the document body.\n\n## Audio Properties\nThe custom CSS properties that **css-audio** provides are as follows.\n\n### `--audio-src`\nThe `--audio-src` property sets one or more audio sources on an element.\n\n#### Syntax\nEach audio source is specified as a `url(...)` value.\n\nTo specify multiple audio sources, supply multiple values separated by a comma:\n\n```\n--audio-src:\n  url(audio1.ogg),\n  url(audio2.ogg);\n```\n\n#### Values\n* **\u003curl\u0026gt;**\n  * Is a [\u003curl\u0026gt;](https://developer.mozilla.org/en-US/docs/Web/CSS/url) denoting the audio source to use. There can be several of them, separated by commas.\n\n### `--audio-state`\nThe `--audio-state` property sets the desired state of the audio.\n\nChanges to this property through selectors or other changes (such as style, class, or id) will result in the audio's state changing.\n\n#### Syntax\nEach audio source's state is specified as a String value.\n\nTo specify the state of multiple audio sources, supply multiple values separated by a comma:\n\n```\n--audio-state:\n  playing,\n  default;\n```\n\n#### Values\n* **default**\n  * The audio state should remain in whatever state it already is.\n* **playing**\n  * The audio should be playing.\n* **paused**\n  * The audio should pause its playback.\n* **stopped** *default*\n  * The audio should stop its playback.\n\n### `--audio-volume`\nThe `--audio-volume` property sets the audio volume from 0 to 100%.\n\n#### Syntax\nThe audio volume is specified as a value from 0 to 100, representing the percentage volume to reduce or increase by.\n\n### `--audio-playback`\nThe `--audio-playback` property sets how the audio should manage playback.\n\n#### Syntax\nEach audio source's playback method is specified as a String value.\n\nTo specify the playback method of multiple audio sources, supply multiple values separated by a comma:\n\n```\n--audio-playback:\n  playthrough,\n  cease;\n```\n\n#### Values\n* **playthrough**\n  * The audio should keep playing until it finishes if the `--audio-state` changes to a non-playing value.\n* **cease** *default*\n  * The audio should change its state to match `--audio-state` immediately.\n\n### `--audio-loop`\nThe `--audio-loop` property sets how the audio should loop.\n\n#### Syntax\nEach audio source's looping rule is specified as either a Number or the `infinite` value.\n\nTo specify the looping rule of multiple audio sources, supply multiple values separated by a comma:\n\n```\n--audio-loop:\n  infinite,\n  2;\n```\n\n#### Values\n* **infinite**\n  * The audio should resume playback from `--audio-offset` once it finishes playing.\n* **\u0026lt;integer\u003e**\n  * The audio should loop the supplies amount of times. *Defaults to \"1\"*\n\n### `--audio-ontrigger`\nThe `--audio-ontrigger` property sets how playback should behave when the audio source updates.\n\n#### Syntax\nEach audio source's trigger rule is specified as a String value.\n\nTo specify trigger rules for multiple audio sources, supply multiple values separated by a comma:\n\n```\n--audio-trigger:\n  reset,\n  multi;\n```\n\n#### Values\n* **continue** *default*\n  * The audio should continue playing if the audio is still playing.\n* **reset**\n  * The audio should immediately reset to the beginning of its offset and play.\n* **multi**\n  * The audio should create a new audio playback source that copies its rules and begin playback.\n\n### `--audio-offset`\nThe `--audio-offset` property sets the playback offset for the audio source to start from.\n\n#### Syntax\nEach audio source's offset rule is specified as a `\u003ctime\u003e` value.\n\nThe specify offset rules for multiple audio sources, supply multiple values separated by a comma:\n\n```\n--audio-offset:\n  0.1s,\n  500ms;\n```\n\n#### Values\n* **\u0026lt;time\u003e**\n  * Is a [\u0026lt;time\u003e](https://developer.mozilla.org/en-US/docs/Web/CSS/time) denoting the offset of the audio. There can be several of them, separated by commas. *Defaults to \"0s\"*\n\n### `--audio-hold-navigation`\nThe `--audio-hold-navigation` property prevents the element from navigating the browser until any playing audio on the element has finished playback.\n\n#### Syntax\n```\n--audio-hold-navigation: finished;\n```\n\n#### Values\n* **finished**\n  * The element is prevented from navigating the page until the element's audio playback is complete.\n\n## Advanced Usage\n### Initialization Options\n**css-audio** can be passed a configuration object through the `init()` call, thereby changing some of the core functionality of **css-audio** to fit your needs.\n\nThese options and their effects are:\n\n| Option            | Description   |  Value(s) | Default Value |\n|-------------------|---------------|-----------|---------------|\n| processDOM        | Should the DOM should be processed on init? | true/false | true |\n| observeDOM        | Should the DOM be observed for added Elements? | true/false | true |\n| observeNodeConfig | Options for MutationObserver.observe used on Nodes | See [MutationObserverInit](https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver#MutationObserverInit) | `{ attributeFilter: ['style', 'class', 'id'] }` |\n| observeDOMConfig  | Options for MutationObserver.observe used on the DOM | See [MutationObserverInit](https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver#MutationObserverInit) | { childList: true } |\n| selectors         | CSS selectors that should trigger handleAudioState for Nodes | Array of Strings | ['active', 'hover', 'focus', 'checked'] |\n\n## Current Limitations\n  * There is no proper triggering of children when the parent changes.\n  \n---  \n  * Internal parsing for Element watching validity requires overspecific rules that specify the full class name, id, and tag name. Additionally, complex psuedo-class selectors will also not register.\n\n```\n\u003cdiv class='button' id='unique'\u003eclick\u003c/div\u003e\n```\n\n```\ndiv.button#unique:active:hover {\n  /* NO MATCH */\n}\ndiv.button#unique:active {\n  /* MATCH */\n}\ndiv.button:active {\n  /* NO MATCH */\n}\ndiv:active {\n  /* NO MATCH */*\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkettek%2Fcss-audio","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkettek%2Fcss-audio","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkettek%2Fcss-audio/lists"}