layout | group | subgroup | title | menu_title | menu_order | version | github_link |
---|---|---|---|---|---|---|---|
default |
fedg |
D_CSS_G |
Simple ways to customize a theme's styles |
Simple ways to customize a theme's styles |
1 |
2.0 |
frontend-dev-guide/css-guide/css_quick_guide_approach.md |
To extend the parent theme's styles in your theme:
- In your theme directory, create a
web/css/source
sub-directory. - Create a
_extend.less
file there. The path to it looks like following:<theme_dir>/ │ ├── web/ │ │ ├── css/ │ │ │ ├── source/ │ │ │ ├──_extend.less ...
- Add your LESS code in this file.
Extending a theme using _extend.less
is the simplest option when you are happy with everything the parent theme has, but want to add more styles.
To override parent styles (that is, override default Magento UI library variables):
- In your theme directory, create a
web/css/source
sub-directory. - Create a
_theme.less
file here. The path to it then looks like following:<theme_dir>/ │ ├── web/ │ │ ├── css/ │ │ │ ├── source/ │ │ │ ├──_theme.less ...
- Copy all variables you need from the parent
_theme.less
, including those which will not be changed. For example if your theme inherits from Blank, the_theme.less
you should copy from is located at<Magento_Blank_theme_dir>/web/css/source/_theme.less
- Make the necessary changes.
It is important to remember that your _theme.less
overrides the parent _theme.less
.
The drawback of this approach is that you need to monitor and manually update your files whenever the parent's _theme.less
is updated.
To make your changes easier to read and support, structure them by adding a separate overriding or extending .less
files for each Magento UI library component you change. Let's use the button
component implemented in _button.less
as an illustration.
- In your theme directory, create a
web/css/source
sub-directory. - Add
_buttons_extend.less
and_extend.less
here. The path to the files looks like following:<theme_dir> │ ├── web/ │ │ ├── css/ │ │ │ ├── source/ │ │ │ ├──_buttons_extend.less │ │ │ ├──_extend.less ...
- In
_buttons_extend.less
add your styles for the button component. -
In
_extend.less
register the_buttons_extend.less
by adding the following code:@import '_buttons_extend.less';
- In your theme directory, create a
web/css/source
sub-directory. - Create a
_buttons.less
file here. The path to it looks like following:<theme_dir>/ │ ├── web/ │ │ ├── css/ │ │ │ ├── source/ │ │ │ ├──_buttons.less ...
This file overrides the
_buttons.less
of the parent theme. - Add your styles for the button component. If the file is left blank, then no styles are applied for the component.