To expand on Alex's answer above, you will need to use CSS/LESS for styling as you can't directly do it inline in XML.
- Create a stylesheet for your module.
Vendor\Module\view\frontend\web\css\source\_module.less
- Add your CSS/LESS styling to that sheet
- If in
developer
mode:
- Clear the
pub/static
cached files with: rm -rf pub/static/
- Clear the
var/view_preprocessed
cached files with: rm -rf var/view_preprocessed
- If in
production
mode:
- Deploy static content:
php bin/magento setup:static-content:deploy
- If caches are enabled
- Clear the cache:
php bin/magento cache:clean
- Refresh the page
NOTE: I've seen some other sources suggest that you need to run an upgrade. I didn't need to in developer
mode but wanted to mention it in case others find it necessary. php bin/magento setup:upgrade
Also worth mentioning that you can use an ID as well as an HTML Class. In your XML you can set these to the container
with the following syntax:
Set ID:
<container name="custom.container" as="custom_container" htmlTag="div" label="Custom Container" htmlId="custom_css_id" />
Set Class:
<container name="custom.container" as="custom_container" htmlTag="div" label="Custom Container" htmlClass="custom_css_class" />
Set ID and Class:
<container name="custom.container" as="custom_container" htmlTag="div" label="Custom Container" htmlId="custom_css_id" htmlClass="custom_css_class" />