How can I replace the HTML Class of the top links block? I thought I can do it by overriding this class https://github.com/magento/magento2/blob/2.4-develop/lib/internal/Magento/Framework/View/Element/Html/Links.php

But not sure if it is the right thing to do, please advise.


You can add class using argument

<block class="Magento\Framework\View\Element\Html\Links" name="top.links">
        <argument name="css_class" xsi:type="string">custom_class</argument>

To add the class to link, for example I've added custom-class to registration link as below in default.xml

<referenceBlock name="top.links">
    <block class="Magento\Customer\Block\Account\RegisterLink" name="register-link">
            <argument name="label" xsi:type="string" translate="true">Create an Account</argument>
            <argument name="class" xsi:type="string" translate="true">custom-class</argument>
  • That is the main one, what I am trying to change is the inner links i.e login, it has links class, I want to change that for example. – Ibrahim S Mar 20 at 17:25
  • The links class you saw is in the template, so you need to overwrite template to get what you want, the Html/Links can't help it – Jimmy Mar 22 at 3:49
  • @IbrahimS I've updated my answer, please check it will help you. – Rahul Barot Mar 22 at 5:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.