How to add a display format for the field I have a field of list type in my custom content type. The display format of list type field has two options default(value) and key.  In my case i want third option which will display "key and value". How can i add third option or get the key/value for the field.
Here is an example on how to create custom field formatters

https://github.com/npinos/drupal8-field-formatters

You can directly specify the markup like this extending the FormatterBase class:

&lt;?php
/**
 * @file
 * Contains Drupal\drupal8_field_formatters\Plugin\Field\FieldFormatter\MainHeadingFormatter.
 */
namespace Drupal\drupal8_field_formatters\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FormatterBase;
use Drupal\Core\Field\FieldItemListInterface;
/**
 * Plugin implementation of the 'main_heading_formatter' formatter.
 *
 * @FieldFormatter(
 *   id = "main_heading_formatter",
 *   label = @Translation("Heading 1"),
 *   weight = "10",
 *   field_types = {
 *     "string",
 *     "text",
 *   },
 *   quickedit = {
 *     "editor" = "plain_text"
 *   }
 * )
 */
class MainHeadingFormatter extends FormatterBase {
  /**
   * {@inheritdoc}
   */
  public function viewElements(FieldItemListInterface $items, $langcode) {
    $element = [];
    foreach ($items as $delta =&gt; $item) {
      // Render each element as markup.
      $element[$delta] = [
        '#type' =&gt; 'markup',
        '#markup' =&gt; '&lt;h1&gt;' . $item-&gt;value . '&lt;/h1&gt;',
      ];
    }
    return $element;
  }
}