How to Customize Shadow-DOM Elements in Audio Player on Webkit and Chrome

Context: In my quest to enhance the appearance of the audio element in Chrome, specifically version 89 on MacOS, I encountered two perplexing issues that I am seeking a deeper understanding of. By utilizing pseudo selectors, I was able to successfully style elements within the audio player by inspecting the shadow DOM through the browser's developer tools. Two rules that were effective are as follows:

::-webkit-media-controls-timeline {background-color: pink;}
audio::-webkit-media-controls-time-remaining-display {background-color: lightgrey;} 

Inquiry: Despite these successes, there are two anomalies that have left me puzzled.

Challenge 1: My attempt to style the first letter within the time-remaining-display div has proven unsuccessful with the following rule:

audio::-webkit-media-controls-time-remaining-display:first-letter {color: white;}

I find it odd that this rule doesn't take effect when similar styling on a regular div works as expected. What is preventing me from targeting and styling the first letter in this case? (The goal here is to eliminate an irritating leading / symbol in the time display).

Challenge 2:

Another puzzling issue arises when trying to style an element with a different pseudo attribute located elsewhere in the shadow DOM using the following rule:

::-internal-track-segment-highlight-before {background-color: blue;}

It's unclear why this rule fails to apply compared to the previous successful color styling. (The aim here is to improve contrast between two sections of the track segment.)

Additionally, I made a slight improvement in contrast by applying:

audio::-webkit-media-controls-timeline {-webkit-filter: brightness(2.5);}

However, the underlying question remains: Why did one method work while the other did not?

Answer №1

Your browser is Chrome, and you have enabled the "Show user agent shadow DOM" setting.

Two Types of ShadowDOM

  • One type is called "userland" shadowDOM,
    which is created by Custom Elements/Web Components developed by third parties (open or closed).

    This type has been available since the implementation of the W3C Web Components standard.

  • The other type is "user-agent" shadowDOM, which is created by each Browser vendor for tags like input, audio, video, select, etc., with variations in implementation between browsers.

    Access to this shadowDOM content is restricted unless the Browser vendor enables access through shadowParts or related technologies. In most cases, it cannot be accessed directly.

    Some pseudo selectors in WebKit can modify certain settings, Reference: Is it possible to style html5 audio tag?

    However, these selectors do not provide full access to manipulate shadowDOM using complex selectors.

    While some Font and Styling settings cascade into shadowDOM to maintain consistent styling across the page. Reference:

Hence, your use of color:red is effective, while :first-letter may not work as expected.

The filter property functions, but background-color might not have the desired effect.

Alternative Solution:

https://github.com/dascritch/cpu-audio offers a reliable Web Component that replaces the standard <audio> tag, providing consistent styling across all browsers.

Note the notation: (open) instead of (user-agent)

Answer №2

video::-webkit-media-controls-timeline {
        background-color: crimson !important;
}

enhances visibility for improved contrast.

(confirmed in video element)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a way to dynamically toggle the visibility of a floating textarea between on and off?

I have my own blog website: Essentially, what I am aiming for is When a user clicks on the search button, a floating semi-transparent textarea window should appear inside the designated rectangle area (as shown in the image, that red orange rectangle). ...

Separate the iframe sessions

I am working with 6 iframes from the same domain but with different URLs and subdirectories. Each iframe sets a cookie with the same name but a different value using the HTML header "set-cookie". To prevent interference between these cookies, I need to fin ...

Tips for detecting the existence of a different class within a div/ul through jquery or javascript?

This is how I have my unordered list, or "ul" element, styled. As you can observe, there are two classes defined for the ul <ul class="nav-second-level collapse"> </ul> There might be an additional class added to the same ul like so: <u ...

Ways to prevent browser scrolling on smartphones and tablets

Having a simple HTML file with an iframe embedded, I have been attempting to prevent my browser from scrolling in both documents. However, this solution works intermittently and does not provide consistent results. I have tried applying various event list ...

For a while now, I've been attempting to transform my paragraph into a block within a section that showcases elements in an inline-flex layout

I have been attempting to adjust the paragraph with the errorDate class so that it displays as a block element directly beneath the input element similar to the image provided here. The section is currently set to appear as an inline-flex. Below is the CS ...

Need to know how to retrieve the li element in a ul that does not have an index of 2? I am aware of how to obtain the index greater than or less

I'm looking to hide all the li elements except for the one with a specific index. I've written some code to achieve this, but I'm wondering if there's a simpler way using jQuery. While jQuery provides methods like eq, gt, and lt, there ...

Issues arise when dealing with the CSS division layout in Internet Explorer 7

Currently in the process of developing a new website and encountering issues with IE7. The first image showcases how it should appear, while the second image depicts how IE7 actually renders it (utilizing IETester to assess older IE versions). The primary ...

focusing on two different sections with a single hover effect

Is it possible to modify the styles of two different divs using CSS when hovering over one div? #down-icn { position: absolute; bottom: 0; right: 25px; color: #fff; -webkit-transition: color 0.25s ease; border-color 0.5s ease; -moz-transition: colo ...

Use PHP code to echo a clear division after every third result in MySQL

I am currently displaying results in descending order from a MySQL table using a while loop. I have already set up a pagination system that displays 9 records per page. However, I am facing an issue when trying to implement a CSS break every 3 records in ...

Resize the shape of an image's polygon

Is there a way to independently scale a specific polygon of an image on hover? For example, I have a world map and I would like to enlarge a country when hovering over it, then return it to its original size when no longer hovering. I am familiar with us ...

Guide on extracting the ID within a for loop and incorporating it into a Vue.js function

In order to make an API request, I need to retrieve the id. However, whenever I try to include <a v-on:click="showRecipe({{inf.Id}})">Recipe</a> in my code, the entire page crashes. Removing this line resolves the issue. How can I pass the id ...

What is the best way to retrieve values from a multi-select dropdown that functions effectively with each selection made

Currently, I am facing an issue in my program where I need to extract values from a multiple select option. The challenge lies in the fact that my view is in a .hbs file and the multiple select is populated using {each}. Here is a snippet of the code: Fir ...

Having trouble submitting a date input form generated with vuejs on Safari browser

I am a huge fan of Vuejs and it's my go-to at work. The other day, I came across a rather perplexing scenario. If you have any insights into this, please do share. Here is the code in question: <script setup lang="ts"> import { ref ...

Identifying the specific random image that has been clicked on in an ASP.NET application

I have 12 unique images randomly selected from 2 different folders. Whenever an image is clicked, I want to change the border color of that image and also save which image was clicked in a database. Below is the code I am currently using to display the ran ...

Is there a way to arrange the components of my form so that the questions are positioned on the left side and the choices are displayed on the right

As I am creating a form, my goal is to align the information within it in a way that places the questions on the left side and the options on the right. I have experimented with utilizing IDs, centering them, and adjusting their positioning from left to r ...

Having trouble loading CSS file in node js after submitting form

Before diving into more details, let me explain my current situation. I am utilizing node's nodemailer to facilitate the process of sending emails based on the information submitted through a form. Initially, everything was functioning smoothly when t ...

How can you create a scenario in Angular Material where items in a toolbar transition to the second line exclusively on mobile screens?

Visit the Angular Material website to see how the toolbar appears on a desktop: https://material.angular.io/ https://i.sstatic.net/KPFMv.png On mobile devices, the menu items Components, CDK, and Guides are displayed on the second line, while github, the ...

The title element is persistently appearing on the same line

As a beginner, I've created a document with a 3x3 checkerboard using HTML and CSS. However, I'm facing an issue where the heading element is not displaying on a separate line as expected. I believe the problem lies in the CSS styling, specifical ...

Discovering hidden elements using Overflow:hidden

I need help figuring out how to display the cropped part of my text without using scroll bars in css. For example: td { overflow: hidden; } The hidden content is important, but the table property is fixed. table { table-layout: fixed; } I want the ...

Conceal the unstyled element and reveal its adjacent sibling?

I have come across some HTML code that I am unable to modify. Instead of using JS/jQuery, I prefer a solution with cross-browser compatible CSS. The structure of the HTML is as follows: <ul class="list"> <li class="item"> <a hr ...