I created a custom content type that collects different fields of type text. I need some to display in <h2> tags and others to display in <h3> tags. When a page is rendered the fields are displayed in <div> tags instead.

I can alter the field twig template but i don't know if this is the correct approach.

{%
  set classes = [
    'field',
    'field--name-' ~ field_name|clean_class,
    'field--type-' ~ field_type|clean_class,
    'field--label-' ~ label_display,
  ]
%}
{%
  set title_classes = [
    'field--label',
    label_display == 'visually_hidden' ? 'sr-only',
  ]
%}

{% if label_hidden %}
  {% if multiple %}
    <div{{ attributes.addClass(classes, 'field--items') }}>
      {% for item in items %}
        <h2{{ item.attributes.addClass('field--item') }}>{{ item.content }}</h2>
      {% endfor %}
    </div>
  {% else %}
    {% for item in items %}
      <h2{{ attributes.addClass(classes, 'field--item') }}>{{ item.content }}</h2>
    {% endfor %}
  {% endif %}
{% else %}
  <div{{ attributes.addClass(classes) }}>
    <div{{ title_attributes.addClass(title_classes) }}>{{ label }}</div>
    {% if multiple %}
      <div class="field--items">
    {% endif %}
    {% for item in items %}
      <h2{{ item.attributes.addClass('field--item') }}>{{ item.content }}</h2>
    {% endfor %}
    {% if multiple %}
      </div>
    {% endif %}
  </div>
{% endif %}