# how to center align buttons

**URL:** <https://community.hubspot.com/t/how-to-center-align-buttons/34106>\
**Category:** CMS Development\
**Tags:** professional\
**Created:** [March 18, 2021, 3:52pm UTC](https://community.hubspot.com/t/how-to-center-align-buttons/34106 "2021-03-18T15:52:05Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![SvanWijngaarden](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/svanwijngaarden/32/81360_2.png) [@SvanWijngaarden](https://community.hubspot.com/u/SvanWijngaarden)\
**Post date:** [March 18, 2021, 3:52pm UTC](https://community.hubspot.com/t/how-to-center-align-buttons/34106/1 "2021-03-18T15:52:05Z")

</div>

Hi all,

I’ve been building a few landingpages with a copy of the default HS template. Works very good, except I can’t figure out for the world how to make the buttons center align within a column. They always stick to the left. I’ve been looking in the settings \> themes part, I’ve been through the CSS code, but nothing worked. Anyone got a sugestion?

Thnx!

---

<div class="post-metadata">

**Author:** ![dennisedson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dennisedson/32/28044_2.png) [@dennisedson](https://community.hubspot.com/u/dennisedson)\
**Post date:** [March 22, 2021, 2:31pm UTC](https://community.hubspot.com/t/how-to-center-align-buttons/34106/2 "2021-03-22T14:31:37Z")

</div>

@SvanWijngaarden , could you add a link to a page with the issue?

---

<div class="post-metadata">

**Author:** ![SvanWijngaarden](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/svanwijngaarden/32/81360_2.png) [@SvanWijngaarden](https://community.hubspot.com/u/SvanWijngaarden)\
**Post date:** [March 23, 2021, 7:22pm UTC](https://community.hubspot.com/t/how-to-center-align-buttons/34106/3 "2021-03-23T19:22:54Z")

</div>

Hi Dennis,

A good example of this is [https://samenrisicobewust.schoutenzekerheid.nl](https://samenrisicobewust.schoutenzekerheid.nl). De page is in dutch, but when you scroll down you can see that the last button is aligned quite akwardly. Hope you be able to put me in the right direction!

Thnx,

Sjoerd

---

<div class="post-metadata">

**Author:** ![dennisedson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dennisedson/32/28044_2.png) [@dennisedson](https://community.hubspot.com/u/dennisedson)\
**Post date:** [March 23, 2021, 7:34pm UTC](https://community.hubspot.com/t/how-to-center-align-buttons/34106/4 "2021-03-23T19:34:53Z")

</div>

Thanks @SvanWijngaarden

The quick fix is adding a style to the head of the page which you can find in the advanced setting of the page editor.

```lia-code-sample
<style>
#hs_cos_wrapper_widget_1616077634088{text-align: center}
</style>

```

The better solution would add justification option to the button module that is being used.

@Anton , do you have any additional ideas?

---

<div class="post-metadata">

**Author:** ![Anton](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/anton/32/103167_2.png) [@Anton](https://community.hubspot.com/u/Anton)\
**Post date:** [March 23, 2021, 9:33pm UTC](https://community.hubspot.com/t/how-to-center-align-buttons/34106/5 "2021-03-23T21:33:55Z")

</div>

Hi @SvanWijngaarden,

seems like @dennisedson trick solved everything!

Nevertheless - If you plan to build multiple pages with a CTA section as the last element and would like to always center it you could do it a bit more generic like this:

```lia-code-sample
.dnd-module:last-of-type a.button{
text-align:center;
}

```

Also: @dennisedson idea of putting a justification option to the button is great since it’s a “cleaner” solution but requires a bit more work. But I’ll try to guide you. Since you’re using the “session”-theme you’d need to:

1. find the button.module of your theme(most likely located in the modules folder of your theme in the design-manager).
2. modify it
  1. First I would add a select option (can be found in the right-sidebar) for simple handling in the future I would add a select option and give it following values/names  
Name of select option(very top in the right sidebar): Button position  
- name: Left / value: flex-start  
- name: Center / value: center  
- name: Right / value: flex-end
  2. copy/paste the code below

3. save the button
4. go to your page and select the option where you’d like to position of the button

code for replacement:

```lia-code-sample
{{ require_css }}
<style>
.horz-{{ module.button_position }}{
display:flex;
flex-direction:column;
flex-wrap:no-wrap;
justify-content:flex-start;
align-items: {{ module.button_position }};
align-content:center;
}
</style>
{{ end_require_css}}
{% if module.button_link.url.type is equalto 'EMAIL_ADDRESS' %}
 {% set href = 'mailto:' ~ module.button_link.url.href %}
{% elif module.button_link.url.href == '/' %}
 {% set href = module.button_link.url.href %}
{% else %}
 {% unless (module.button_link.url.href is string_containing '//') or !module.button_link.url.href %}
 {% set href = '//' ~ module.button_link.url.href %}
 {% else %}
 {% set href = module.button_link.url.href || '' %}
 {% endunless %}
{% endif %}

{% set rel = (module.button_link.open_in_new_tab ? 'noopener ' : null) ~ (module.button_link.no_follow ? 'nofollow' : null) %}
<div class="horz-{{module.button_position}}">
<{% if module.button_options.button_link_toggle == true %}a href="{{ href }}" {% else %}button {% endif %} class="button{% if module.style.button_type == 'secondary' %} button--secondary{% elif module.style.button_type == 'simple' %} button--simple{% endif %}{% if module.style.button_size == 'small' %} button--small{% elif module.style.button_size == 'large' %} button--large{% endif %}{% if module.button_icon.icon_position == 'right' %} button--icon-right{% endif %}"
 id="button_{{ name }}"
 {% if module.button_link.open_in_new_tab %}target="_blank"{% endif %}
 rel="{{ rel }}">

 {% if module.button_options.button_icon_toggle == true and module.button_icon.icon_field.unicode %}
 {% icon
 extra_classes='button__icon'
 name='{{ module.button_icon.icon_field.name }}'
 purpose='decorative'
 style='{{ module.button_icon.icon_field.type }}'
 unicode='{{ module.button_icon.icon_field.unicode }}'
 %}
 {% endif %}
 {{ module.button_text }}

</{% if module.button_options.button_link_toggle == true %}a{% else %}button{% endif %}>
</div>

```

It’s a very technical solution but eliminates the need of editing your template/CSS permanently 😀

@dennisedson - how about implementing something like that as a default feature of the default button module?

best,

Anton

---

<div class="post-metadata">

**Author:** ![SvanWijngaarden](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/svanwijngaarden/32/81360_2.png) [@SvanWijngaarden](https://community.hubspot.com/u/SvanWijngaarden)\
**Post date:** [March 26, 2021, 10:53am UTC](https://community.hubspot.com/t/how-to-center-align-buttons/34106/6 "2021-03-26T10:53:34Z")

</div>

Hi both! Thanks for your help! I think this is the solution. @Anton can you please tell me what code I need to replace, or where to put the code above? I managed to add the justification option to the buttons, but they’re obviously not yet working.

Thanks!

Best,

Sjoerd

---

<div class="post-metadata">

**Author:** ![Anton](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/anton/32/103167_2.png) [@Anton](https://community.hubspot.com/u/Anton)\
**Post date:** [March 26, 2021, 9:58pm UTC](https://community.hubspot.com/t/how-to-center-align-buttons/34106/7 "2021-03-26T21:58:41Z")

</div>

Hi @SvanWijngaarden,

1. open the design-manager(marketing/files/design-manager)
2. open your theme folder. It seems that you’re using session (you’ll find it in the @hubspot folder)
3. navigate to the module folder and open the button module
4. cut the hole part from the html+hubl section and paste the code from above into it.
5. Add a select option how described above

best,

Anton

---

<div class="post-metadata">

**Author:** ![SvanWijngaarden](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/svanwijngaarden/32/81360_2.png) [@SvanWijngaarden](https://community.hubspot.com/u/SvanWijngaarden)\
**Post date:** [March 29, 2021, 8:49am UTC](https://community.hubspot.com/t/how-to-center-align-buttons/34106/8 "2021-03-29T08:49:06Z")

</div>

Thats it! Thanks!

Best,

Sjoerd

---

<div class="post-metadata">

**Author:** ![cbangs](https://avatars.discourse-cdn.com/v4/letter/c/aeb1de/32.png) [@cbangs](https://community.hubspot.com/u/cbangs)\
**Post date:** [April 19, 2022, 6:45pm UTC](https://community.hubspot.com/t/how-to-center-align-buttons/34106/9 "2022-04-19T18:45:42Z")

</div>

Thanks for this solution, I’m new to Hubspot and it worked great. I had trouble finding the “select option” in step 2 (perhaps it was renamed). Adding clarity to step 2.1 of the answer:

1. In the “Fields” section, click “Add field”
2. Select “Choice”, located under the Boolean label
3. Proceed with the rest of step 2

Another note: these instructions add a selector dropdown to the Button module UI. They do not add the “Alignment” button group that’s in the Styles tab of other modules—see screenshot for reference. I named my field “Button alignment” to match the labeling pattern of the other options.

 ![Screen Shot 2022-04-19 at 11.32.58 AM.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/7/2/72e55d444dbe27951f9a4e325bc644c3e6847711.png)

 ![Screen Shot 2022-04-19 at 11.42.20 AM.png](https://d2qpr2jzcazej7.cloudfront.net/original/2X/b/b121482782091755e424e290b093419b0e326ec0.png)

---

<div class="post-metadata">

**Author:** ![RLanzani](https://avatars.discourse-cdn.com/v4/letter/r/e68b1a/32.png) [@RLanzani](https://community.hubspot.com/u/RLanzani)\
**Post date:** [April 12, 2023, 7:50am UTC](https://community.hubspot.com/t/how-to-center-align-buttons/34106/10 "2023-04-12T07:50:47Z")

</div>

Hi Anton,

thank you.

I just used your code and done every step and it works for the alignment.

Now i have a new problem cause the internal links it doesn’t work.

Usually in my landing page i use to give id to some elements and use it for the buttons.

I don’t know how to resolve it.

Im gonna attach here a screenshot of the code:

 ![Screenshot 2023-04-12 at 09.47.44.jpg](https://d2qpr2jzcazej7.cloudfront.net/original/2X/f/f3954cda6c3dd1547c27a739346c7d6d72d363f0.jpeg)

 ![Screenshot 2023-04-12 at 09.49.57.png](https://d2qpr2jzcazej7.cloudfront.net/original/2X/1/1c1b106944281bc8437c573e6fa0d359b46e5838.png)  
Thank you,

Riccardo

---

<div class="post-metadata">

**Author:** ![MHudsonCW](https://avatars.discourse-cdn.com/v4/letter/m/278dde/32.png) [@MHudsonCW](https://community.hubspot.com/u/MHudsonCW)\
**Post date:** [October 24, 2023, 7:46pm UTC](https://community.hubspot.com/t/how-to-center-align-buttons/34106/11 "2023-10-24T19:46:17Z")

</div>

Hi Anton,  
I have tried this for the center button. Though it does create a centered button, the text is no longer centered and aligned to the left. I added the justification section as described above but that does not seem to do anything. Can you please provide an update if this still works?

---

<div class="post-metadata">

**Author:** ![L0rdOskar](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/l0rdoskar/32/197072_2.png) [@L0rdOskar](https://community.hubspot.com/u/L0rdOskar)\
**Post date:** [December 1, 2022, 8:22pm UTC](https://community.hubspot.com/t/how-to-center-align-buttons/34106/12 "2022-12-01T20:22:36Z")

</div>

Hello I’ve tried this but when I add the code the button gets its own gravity and pulls in other elements xD

**In the Editor** :

 ![Skärmavbild 2022-12-01 kl. 21.15.05.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/f/7/f71e09f212aa6ba30f78f833eb406b56d0caeb52.png)

\*\*On live site:

 ![Skärmavbild 2022-12-01 kl. 21.15.11.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/8/6/863eddba70bd040c82f55cdf61373ab728f48e78.png)  
\*\*

**Here is the code for my button before changes:**

```lia-code-sample
{% if module.link.url.type is equalto 'EMAIL_ADDRESS' %}
 {% set href = 'mailto:' ~ module.link.url.href %}
{% elif module.link.url.href == '/' %}
 {% set href = module.link.url.href %}
{% else %}
 {% unless (module.link.url.href is string_containing '//') or !module.link.url.href %}
 {% set href = '//' ~ module.link.url.href %}
 {% else %}
 {% set href = module.link.url.href || '' %}
 {% endunless %}
{% endif %}

{% set rel = [] %}
{% if module.link.no_follow %}
 {% do rel.append("nofollow") %}
{% endif %}
{% if module.link.open_in_new_tab %}
 {% do rel.append("noopener") %}
{% endif %}

<a class="button bg-{{ module.use_custom_colors }}" href="{{ href }}"

 {% if module.link.open_in_new_tab %}target="_blank"{% endif %}
{% if rel %}rel="{{ rel|join(' ') }}"{% endif %}
>
 {{ module.button_text }}
</a>

```

**Here is the code for when I try to add your code:**

```lia-code-sample
{{ require_css }}
<style>
.horz-{{ module.button_position }}{
display:flex;
flex-direction:column;
flex-wrap:no-wrap;
justify-content:flex-start;
align-items: {{ module.button_position }};
align-content:center;
}
</style>
{{ end_require_css}}

{% if module.link.url.type is equalto 'EMAIL_ADDRESS' %}
{% set href = 'mailto:' ~ module.link.url.href %}
{% elif module.link.url.href == '/' %}
{% set href = module.link.url.href %}
{% else %}
{% unless (module.link.url.href is string_containing '//') or !module.link.url.href %}
{% set href = '//' ~ module.link.url.href %}
{% else %}
{% set href = module.link.url.href || '' %}
{% endunless %}
{% endif %}

{% set rel = [] %}
{% if module.link.no_follow %}
{% do rel.append("nofollow") %}
{% endif %}
{% if module.link.open_in_new_tab %}
{% do rel.append("noopener") %}
{% endif %}

<div class="horz-{{module.button_position}}">
<{% if module.button_options.button_link_toggle == true %}a href="{{ href }}" {% else %}button {% endif %} class="button
{% if module.style.button_type == 'secondary' %} button--secondary{% elif module.style.button_type == 'simple' %} button--simple{% endif %}
{% if module.style.button_size == 'small' %} button--small{% elif module.style.button_size == 'large' %} button--large{% endif %}
{% if module.button_icon.icon_position == 'right' %} button--icon-right{% endif %}"
id="button_{{ name }}"
{% if module.button_link.open_in_new_tab %}target="_blank"{% endif %}
rel="{{ rel }}">

<a class="button bg-{{ module.use_custom_colors }}" href="{{ href }}"

{% if module.link.open_in_new_tab %}target="_blank"{% endif %}
{% if rel %}rel="{{ rel|join(' ') }}"{% endif %}
>
{{ module.button_text }}
</a>

```
