diff --git a/files/en-us/learn_web_development/extensions/forms/advanced_form_styling/index.md b/files/en-us/learn_web_development/extensions/forms/advanced_form_styling/index.md index 40860c7621de1d6..720345f70913171 100644 --- a/files/en-us/learn_web_development/extensions/forms/advanced_form_styling/index.md +++ b/files/en-us/learn_web_development/extensions/forms/advanced_form_styling/index.md @@ -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 ``](/en-US/docs/Web/HTML/Element/input/color) - Date-related controls such as [``](/en-US/docs/Web/HTML/Element/input/datetime-local) - [``](/en-US/docs/Web/HTML/Element/input/range) @@ -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 `` 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 `` 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: @@ -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. diff --git a/files/en-us/learn_web_development/extensions/forms/basic_native_form_controls/index.md b/files/en-us/learn_web_development/extensions/forms/basic_native_form_controls/index.md index 89a36da4592a7e0..672e7bb2c7b4af8 100644 --- a/files/en-us/learn_web_development/extensions/forms/basic_native_form_controls/index.md +++ b/files/en-us/learn_web_development/extensions/forms/basic_native_form_controls/index.md @@ -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) diff --git a/files/en-us/learn_web_development/extensions/forms/customizable_select/index.md b/files/en-us/learn_web_development/extensions/forms/customizable_select/index.md new file mode 100644 index 000000000000000..47e9e277d429d6c --- /dev/null +++ b/files/en-us/learn_web_development/extensions/forms/customizable_select/index.md @@ -0,0 +1,400 @@ +--- +title: Customizable select elements +slug: Learn_web_development/Extensions/Forms/Customizable_select +page-type: learn-module-chapter +--- + +{{LearnSidebar}} + +This article explains how to use dedicated, modern HTML and CSS features together to create fully-customized {{htmlelement("select")}} elements. This includes having full control over styling the select button, drop-down picker, arrow icon, current selection checkmark, and each individual {{htmlelement("option")}} element. + +## Background + +Traditionally it has been difficult to customize the look and feel of `` element to strip away some of the OS-level styling, and then use CSS to customize the bits that can be styled. This technique is explained in [Advanced form styling](/en-US/docs/Learn_web_development/Extensions/Forms/Advanced_form_styling). + +Customizable `` elements using the following HTML and CSS features: + +- Plain old {{htmlelement("select")}}, {{htmlelement("option")}}, and {{htmlelement("optgroup")}} elements. These work just the same as in "classic" selects, except that they have additional permitted content types. The new features are built on top of existing select functionality as progressive enhancements, meaning that customizable selects can be designed to fall back to "classic" selects in non-supporting browsers. +- A {{htmlelement("button")}} element included as the first child inside the `` element. This is comonly known as the **select {{htmlelement("button")}}** (as it is the button you need to press to open the drop-down picker). + > [!NOTE] + > The select ` + + + + + + + + + +

+ +``` + +> [!NOTE] +> The [`aria-hidden="true"`](/en-US/docs/Web/Accessibility/ARIA/Reference/Attributes/aria-hidden) attribute is included on the icons so that they will be hidden from assistive technologies, avoiding the option values being annouced twice (for example, "cat cat"). + +The example markup is nearly the same as "classic" ``, but be careful when doing this. What you render can alter the `` contents represents the drop-down picker, which is usually limited to the `