Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Technical review: Document customizable <select> elements #38470

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
4e4b77c
Document customizable <select> elements
chrisdavidmills Mar 5, 2025
db40b51
fix typo
chrisdavidmills Mar 5, 2025
e55d318
Finish guide
chrisdavidmills Mar 6, 2025
fd5ecff
Merge branch 'main' into customizable-select
chrisdavidmills Mar 7, 2025
029cb9d
correct info about how <selectedcontent> is populated
chrisdavidmills Mar 7, 2025
80b9f67
add links to customizable select guide, update existing pages, remove…
chrisdavidmills Mar 7, 2025
9998430
Document selectedcontent element
chrisdavidmills Mar 7, 2025
4dc3040
Add doc for ::picker()
chrisdavidmills Mar 10, 2025
edbc2b1
Document appearance: base-select, tweak :open and :checked ref pages
chrisdavidmills Mar 10, 2025
afdbacb
Document the ::picker-icon and ::checkmark pseudos
chrisdavidmills Mar 10, 2025
28e9f6e
Add notes on implicit popover-invoker relationship and anchor reference
chrisdavidmills Mar 10, 2025
c33195c
Merge branch 'main' into customizable-select
chrisdavidmills Mar 10, 2025
86b1c9a
Add default picker styling info, tweak other info
chrisdavidmills Mar 10, 2025
07a09fc
Merge branch 'customizable-select' of github.com:chrisdavidmills/cont…
chrisdavidmills Mar 10, 2025
3e635cc
Merge branch 'main' into customizable-select
chrisdavidmills Mar 14, 2025
c0063ff
Fixes for josepharhar review comments
chrisdavidmills Mar 15, 2025
3e5babe
Merge branch 'customizable-select' of github.com:chrisdavidmills/cont…
chrisdavidmills Mar 15, 2025
25bbe3d
Fixes for josepharhar review comments
chrisdavidmills Mar 18, 2025
575f19e
Fixes for scottaohara review comments
chrisdavidmills Mar 19, 2025
97b6e43
Accessibility and <select> content fixes
chrisdavidmills Mar 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ To recap what we said in the previous article, we have:
**The ugly**: Some elements can't be styled thoroughly using CSS. These include:

- Elements involved in creating dropdown widgets, including {{HTMLElement("select")}}, {{HTMLElement("option")}}, {{HTMLElement("optgroup")}} and {{HTMLElement("datalist")}}.
> [!NOTE]
> Many modern browsers now support [Customizable select elements](/en-US/docs/Learn_web_development/Extensions/Forms/Customizable_select), a set of HTML and CSS features that together enable full customization of `<select>` elements and their contents just like any regular DOM elements.
- [`<input type="color">`](/en-US/docs/Web/HTML/Element/input/color)
- Date-related controls such as [`<input type="datetime-local">`](/en-US/docs/Web/HTML/Element/input/datetime-local)
- [`<input type="range">`](/en-US/docs/Web/HTML/Element/input/range)
Expand Down Expand Up @@ -367,9 +369,11 @@ Let's talk about some specifics of each of these types of control, highlighting

### Selects and datalists

In modern browsers, selects and datalists are generally not too bad to style provided you don't want to vary the look and feel too much from the defaults.
Selects are generally not too bad to style. Many modern browsers now support [Customizable select elements](/en-US/docs/Learn_web_development/Extensions/Forms/Customizable_select), a set of HTML and CSS features that together enable full customization of `<select>` elements and their contents just like any regular DOM elements. In supporting browsers and codebases, you don't need to worry about these legacy techniques any more.

We've managed to get the basic look of the boxes looking pretty uniform and consistent. The datalist control is `<input type="text">` anyway, so we knew this wouldn't be a problem.
Datalist styling is still limited.

For datalists, and for selects in browsers that don't support customizable selects, you can get an OK level of customization provided you don't want to vary the look and feel too much from the defaults. We've managed to get the basic look of the boxes looking pretty uniform and consistent. The `datalist` invoking control is an `<input type="text">` anyway, so we knew this wouldn't be a problem.

Two things are slightly more problematic. First of all, the select's "arrow" icon that indicates it is a dropdown differs across browsers. It also tends to change if you increase the size of the select box, or resize in an ugly fashion. To fix this in our example we first used our old friend `appearance: none` to get rid of the icon altogether:

Expand Down Expand Up @@ -518,7 +522,7 @@ In the next article of this module, we will explore the different [UI pseudo-cla

{{PreviousMenuNext("Learn_web_development/Extensions/Forms/Styling_web_forms", "Learn_web_development/Extensions/Forms/UI_pseudo-classes", "Learn_web_development/Extensions/Forms")}}

### Advanced Topics
## See also

- [How to build custom form controls](/en-US/docs/Learn_web_development/Extensions/Forms/How_to_build_custom_form_controls)
- [Sending forms through JavaScript](/en-US/docs/Learn_web_development/Extensions/Forms/Sending_forms_through_JavaScript)
- [Customizable select elements](/en-US/docs/Learn_web_development/Extensions/Forms/Customizable_select)
- : This article explains how to use dedicated, modern HTML and CSS features together to create fully-customized {{htmlelement("select")}} elements.
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,3 @@ You've reached the end of this article, but can you remember the most important
This article has covered the older input types — the original set introduced in the early days of HTML that is well-supported in all browsers. In the next section, we'll take a look at the more modern values of the `type` attribute.

{{PreviousMenuNext("Learn_web_development/Extensions/Forms/How_to_structure_a_web_form", "Learn_web_development/Extensions/Forms/HTML5_input_types", "Learn_web_development/Extensions/Forms")}}

### Advanced Topics

- [How to build custom form controls](/en-US/docs/Learn_web_development/Extensions/Forms/How_to_build_custom_form_controls)
- [Sending forms through JavaScript](/en-US/docs/Learn_web_development/Extensions/Forms/Sending_forms_through_JavaScript)

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -867,8 +867,3 @@ Once you have checked that the form is filled out correctly, the form can be sub
We'll cover [sending form data](/en-US/docs/Learn_web_development/Extensions/Forms/Sending_and_retrieving_form_data) next.

{{PreviousMenuNext("Learn_web_development/Extensions/Forms/UI_pseudo-classes", "Learn_web_development/Extensions/Forms/Sending_and_retrieving_form_data", "Learn_web_development/Extensions/Forms")}}

### Advanced Topics

- [How to build custom form controls](/en-US/docs/Learn_web_development/Extensions/Forms/How_to_build_custom_form_controls)
- [Sending forms through JavaScript](/en-US/docs/Learn_web_development/Extensions/Forms/Sending_forms_through_JavaScript)
Original file line number Diff line number Diff line change
Expand Up @@ -2095,24 +2095,3 @@ Here are a few libraries you should consider before coding your own:
- [msDropDown](https://github.com/marghoobsuleman/ms-Dropdown)

If you do create alternative controls via radio buttons, your own JavaScript, or with a 3rd party library, ensure it is accessible and feature-proof; that is, it needs to be able to work better with a variety of browsers whose compatibility with the Web standards they use vary. Have fun!

## See also

### Learning path

- [Your first HTML form](/en-US/docs/Learn_web_development/Extensions/Forms/Your_first_form)
- [How to structure an HTML form](/en-US/docs/Learn_web_development/Extensions/Forms/How_to_structure_a_web_form)
- [The native form controls](/en-US/docs/Learn_web_development/Extensions/Forms/Basic_native_form_controls)
- [HTML5 input types](/en-US/docs/Learn_web_development/Extensions/Forms/HTML5_input_types)
- [Additional form controls](/en-US/docs/Learn_web_development/Extensions/Forms/Other_form_controls)
- [UI pseudo-classes](/en-US/docs/Learn_web_development/Extensions/Forms/UI_pseudo-classes)
- [Styling HTML forms](/en-US/docs/Learn_web_development/Extensions/Forms/Styling_web_forms)
- [Form data validation](/en-US/docs/Learn_web_development/Extensions/Forms/Form_validation)
- [Sending form data](/en-US/docs/Learn_web_development/Extensions/Forms/Sending_and_retrieving_form_data)

### Advanced Topics

- [Sending forms through JavaScript](/en-US/docs/Learn_web_development/Extensions/Forms/Sending_forms_through_JavaScript)
- **How to build custom form controls**
- [HTML forms in legacy browsers](/en-US/docs/Learn_web_development/Extensions/Forms/HTML_forms_in_legacy_browsers)
- [Advanced styling for HTML forms](/en-US/docs/Learn_web_development/Extensions/Forms/Advanced_form_styling)
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,3 @@ You now have all the knowledge you'll need to properly structure your web forms.
- [A List Apart: _Sensible Forms: A Form Usability Checklist_](https://alistapart.com/article/sensibleforms/)

{{PreviousMenuNext("Learn_web_development/Extensions/Forms/Your_first_form", "Learn_web_development/Extensions/Forms/Basic_native_form_controls", "Learn_web_development/Extensions/Forms")}}

### Advanced Topics

- [How to build custom form controls](/en-US/docs/Learn_web_development/Extensions/Forms/How_to_build_custom_form_controls)
- [Sending forms through JavaScript](/en-US/docs/Learn_web_development/Extensions/Forms/Sending_forms_through_JavaScript)
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,3 @@ You've reached the end of this article, but can you remember the most important
That brings us to the end of our tour of the HTML5 form input types. There are a few other control types that cannot be easily grouped due to their very specific behaviors but are still essential to know. We cover those in the next article.

{{PreviousMenuNext("Learn_web_development/Extensions/Forms/Basic_native_form_controls", "Learn_web_development/Extensions/Forms/Other_form_controls", "Learn_web_development/Extensions/Forms")}}

### Advanced Topics

- [How to build custom form controls](/en-US/docs/Learn_web_development/Extensions/Forms/How_to_build_custom_form_controls)
- [Sending forms through JavaScript](/en-US/docs/Learn_web_development/Extensions/Forms/Sending_forms_through_JavaScript)
Original file line number Diff line number Diff line change
Expand Up @@ -143,24 +143,3 @@ Even though some polyfills are very aware of performance, loading additional scr
As you can see, considering browser and operating system default form control appearance is important. There are many techniques to handle these issue; however mastering all of them is beyond the scope of this article. The basic premise is to consider whether altering the default implementation is worth the work before embarking on the challenge.

If you read all the articles of this [HTML Forms guide](/en-US/docs/Learn_web_development/Extensions/Forms), you should now be at ease with using forms. If you discover new techniques or hints, please help improve the guide.

## See also

### Learning path

- [Your first HTML form](/en-US/docs/Learn_web_development/Extensions/Forms/Your_first_form)
- [How to structure an HTML form](/en-US/docs/Learn_web_development/Extensions/Forms/How_to_structure_a_web_form)
- [The native form widgets](/en-US/docs/Learn_web_development/Extensions/Forms/Basic_native_form_controls)
- [HTML5 input types](/en-US/docs/Learn_web_development/Extensions/Forms/HTML5_input_types)
- [Additional form controls](/en-US/docs/Learn_web_development/Extensions/Forms/Other_form_controls)
- [UI pseudo-classes](/en-US/docs/Learn_web_development/Extensions/Forms/UI_pseudo-classes)
- [Styling HTML forms](/en-US/docs/Learn_web_development/Extensions/Forms/Styling_web_forms)
- [Form data validation](/en-US/docs/Learn_web_development/Extensions/Forms/Form_validation)
- [Sending form data](/en-US/docs/Learn_web_development/Extensions/Forms/Sending_and_retrieving_form_data)

### Advanced Topics

- [Sending forms through JavaScript](/en-US/docs/Learn_web_development/Extensions/Forms/Sending_forms_through_JavaScript)
- [How to build custom form widgets](/en-US/docs/Learn_web_development/Extensions/Forms/How_to_build_custom_form_controls)
- **HTML forms in legacy browsers**
- [Advanced styling for HTML forms](/en-US/docs/Learn_web_development/Extensions/Forms/Advanced_form_styling)
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,16 @@ The above text is a good indicator as to why we've put web forms into its own st
- [Sending form data](/en-US/docs/Learn_web_development/Extensions/Forms/Sending_and_retrieving_form_data)
- : This article looks at what happens when a user submits a form — where does the data go, and how do we handle it when it gets there? We also look at some of the security concerns associated with sending form data.

## Advanced articles
## Additional articles

The following articles aren't included in the learning pathway, but they'll prove interesting and useful when you've mastered the above techniques and want to know more.

- [How to build custom form controls](/en-US/docs/Learn_web_development/Extensions/Forms/How_to_build_custom_form_controls)
- : You'll come across some cases where the native form widgets just don't provide what you need, e.g. because of styling or functionality. In such cases, you may need to build your own form widget out of raw HTML. This article explains how you'd do this and the considerations you need to be aware of when doing so, with a practical case study.
- [Sending forms through JavaScript](/en-US/docs/Learn_web_development/Extensions/Forms/Sending_forms_through_JavaScript)
- : This article looks at ways to use a form to assemble an HTTP request and send it via custom JavaScript, rather than standard form submission. It also looks at why you'd want to do this, and the implications of doing so. (See also [Using FormData objects](/en-US/docs/Web/API/XMLHttpRequest_API/Using_FormData_Objects).)
- [Customizable select elements](/en-US/docs/Learn_web_development/Extensions/Forms/Customizable_select)
- : This article explains how to use dedicated, modern HTML and CSS features together to create fully-customized {{htmlelement("select")}} elements.

## See also

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,3 @@ As you'll have seen in the last few articles, there are many types of form contr
Now that you have a grasp of the HTML behind the different available form controls, we'll take a look at [Styling them](/en-US/docs/Learn_web_development/Extensions/Forms/Styling_web_forms).

{{PreviousMenuNext("Learn_web_development/Extensions/Forms/HTML5_input_types","Learn_web_development/Extensions/Forms/Styling_web_forms", "Learn_web_development/Extensions/Forms")}}

### Advanced Topics

- [How to build custom form controls](/en-US/docs/Learn_web_development/Extensions/Forms/How_to_build_custom_form_controls)
- [Sending forms through JavaScript](/en-US/docs/Learn_web_development/Extensions/Forms/Sending_forms_through_JavaScript)
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,3 @@ If you want to learn more about securing a web application, you can dig into the
- [Web Security by Mozilla](https://infosec.mozilla.org/guidelines/web_security)

{{PreviousMenu("Learn_web_development/Extensions/Forms/Form_validation", "Learn_web_development/Extensions/Forms")}}

### Advanced Topics

- [How to build custom form controls](/en-US/docs/Learn_web_development/Extensions/Forms/How_to_build_custom_form_controls)
- [Sending forms through JavaScript](/en-US/docs/Learn_web_development/Extensions/Forms/Sending_forms_through_JavaScript)
Original file line number Diff line number Diff line change
Expand Up @@ -122,24 +122,3 @@ form.addEventListener("submit", (event) => {
We add a submit event handler for the form element. This first calls {{domxref("Event.preventDefault()", "preventDefault()")}} to prevent the browser's built-in form submission, so we can take over. Then we call `sendData()`, which retrieves the form element and passes it into the `FormData` constructor.

After that, we send the `FormData` instance as an HTTP `POST` request, using `fetch()`.

## See also

### Learning path

- [Your first HTML form](/en-US/docs/Learn_web_development/Extensions/Forms/Your_first_form)
- [How to structure an HTML form](/en-US/docs/Learn_web_development/Extensions/Forms/How_to_structure_a_web_form)
- [The native form widgets](/en-US/docs/Learn_web_development/Extensions/Forms/Basic_native_form_controls)
- [HTML5 input types](/en-US/docs/Learn_web_development/Extensions/Forms/HTML5_input_types)
- [Additional form controls](/en-US/docs/Learn_web_development/Extensions/Forms/Other_form_controls)
- [UI pseudo-classes](/en-US/docs/Learn_web_development/Extensions/Forms/UI_pseudo-classes)
- [Styling HTML forms](/en-US/docs/Learn_web_development/Extensions/Forms/Styling_web_forms)
- [Form data validation](/en-US/docs/Learn_web_development/Extensions/Forms/Form_validation)
- [Sending form data](/en-US/docs/Learn_web_development/Extensions/Forms/Sending_and_retrieving_form_data)

### Advanced Topics

- **Sending forms through JavaScript**
- [How to build custom form widgets](/en-US/docs/Learn_web_development/Extensions/Forms/How_to_build_custom_form_controls)
- [HTML forms in legacy browsers](/en-US/docs/Learn_web_development/Extensions/Forms/HTML_forms_in_legacy_browsers)
- [Advanced styling for HTML forms](/en-US/docs/Learn_web_development/Extensions/Forms/Advanced_form_styling)
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ The article [Advanced form styling](/en-US/docs/Learn_web_development/Extensions
- [`<input type="range">`](/en-US/docs/Web/HTML/Element/input/range)
- [`<input type="file">`](/en-US/docs/Web/HTML/Element/input/file)
- Elements involved in creating dropdown widgets, including {{HTMLElement("select")}}, {{HTMLElement("option")}}, {{HTMLElement("optgroup")}} and {{HTMLElement("datalist")}}.
> [!NOTE]
> Many modern browsers now support [Customizable select elements](/en-US/docs/Learn_web_development/Extensions/Forms/Customizable_select), a set of HTML and CSS features that together enable full customization of `<select>` elements and their contents just like any regular DOM elements.
- {{HTMLElement("progress")}} and {{HTMLElement("meter")}}

For example, the date picker calendar, and the button on \<select> that displays an options list when clicked, can't be styled using CSS alone.
Expand Down Expand Up @@ -382,8 +384,3 @@ You've reached the end of this article, but can you remember the most important
As you can see, as long as we want to build forms with just text fields and buttons, it's easy to style them using CSS. [In the next article](/en-US/docs/Learn_web_development/Extensions/Forms/Advanced_form_styling), we will see how to handle form widgets which fall into the "bad" and "ugly" categories.

{{PreviousMenuNext("Learn_web_development/Extensions/Forms/Other_form_controls","Learn_web_development/Extensions/Forms/Advanced_form_styling","Learn_web_development/Extensions/Forms")}}

### Advanced Topics

- [How to build custom form controls](/en-US/docs/Learn_web_development/Extensions/Forms/How_to_build_custom_form_controls)
- [Sending forms through JavaScript](/en-US/docs/Learn_web_development/Extensions/Forms/Sending_forms_through_JavaScript)
Original file line number Diff line number Diff line change
Expand Up @@ -611,8 +611,3 @@ You've reached the end of this article, but can you remember the most important
This completes our look at UI pseudo-classes that relate to form inputs. Keep playing with them, and create some fun form styles! Next up, we'll move on to something different — [client-side form validation](/en-US/docs/Learn_web_development/Extensions/Forms/Form_validation).

{{PreviousMenuNext("Learn_web_development/Extensions/Forms/Advanced_form_styling", "Learn_web_development/Extensions/Forms/Form_validation", "Learn_web_development/Extensions/Forms")}}

### Advanced Topics

- [How to build custom form controls](/en-US/docs/Learn_web_development/Extensions/Forms/How_to_build_custom_form_controls)
- [Sending forms through JavaScript](/en-US/docs/Learn_web_development/Extensions/Forms/Sending_forms_through_JavaScript)
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,3 @@ button {
That's only the beginning, however — now it's time to take a deeper look. Forms have way more power than what we saw here and the other articles in this module will help you to master the rest.

{{NextMenu("Learn_web_development/Extensions/Forms/How_to_structure_a_web_form", "Learn_web_development/Extensions/Forms")}}

### Advanced Topics

- [How to build custom form controls](/en-US/docs/Learn_web_development/Extensions/Forms/How_to_build_custom_form_controls)
- [Sending forms through JavaScript](/en-US/docs/Learn_web_development/Extensions/Forms/Sending_forms_through_JavaScript)
32 changes: 32 additions & 0 deletions files/en-us/web/api/htmlselectedcontentelement/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
title: HTMLSelectedContentElement
slug: Web/API/HTMLSelectedContentElement
page-type: web-api-interface
browser-compat: api.HTMLSelectedContentElement
---

{{APIRef("HTML DOM")}}

The **`HTMLSelectedContentElement`** interface represents a {{HTMLElement("selectedcontent")}} element in the [DOM](/en-US/docs/Web/API/Document_Object_Model).

{{InheritanceDiagram}}

## Instance properties

_This interface has no properties, but inherits properties from: {{DOMxRef("HTMLElement")}}._

## Instance methods

_This interface has no methods, but inherits methods from: {{DOMxRef("HTMLElement")}}._

## Specifications

Not currently part of a specification. See https://github.com/whatwg/html/pull/10633 for the relevant specification PR.

## Browser compatibility

{{Compat}}

## See also

- The HTML element implementing this interface: {{HTMLElement("selectedcontent")}}.
Loading